← CSES Better

Count Ordered Path Decompositions of a Tree

ZIO · 2025 · Zonal Informatics Olympiad · P4

Open official problem ↗
Ask AI

Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.

Open Claude Desktop

trees · paths · combinatorics · dynamic-programming

The organizer’s problem statement is available at the official source link.

tree paths

Every road belongs to exactly one chosen path

Each array element is a simple path between two cities; together, the paths partition the tree edges. Schematic structure only; vertices and edges represent the task relation, not an official sample. Schematic graph only; labels and edges show the task relation, not an official sample.

unique pathpath endpoint Ashared treepath endpoint B
  1. 1

    Choose endpoints

    Each pair (A,B) names the unique simple path between two tree vertices.
  2. 2

    Cover each edge once

    The selected paths must be edge-disjoint and cover every road exactly once.
  3. 3

    Canonicalize order

    Sort the endpoint pairs lexicographically to form the required array; count distinct resulting arrays modulo 997.
Tools
1
2
3
4
5
6
7
8
9
10
11
12
Draft saved locally
|12 lines, 156 chars

Run output

Run your code to see output.