#P14946. Bus Station
Bus Station
Problem Description
There is a tree with nodes. A subset of all simple paths in the tree is called good if and only if:
- Every edge of the tree is covered by exactly one path in .
- Among all sets that satisfy the first condition, the maximum number of times any node appears as an endpoint of a path in is minimized.
Count the number of good sets . Output the answer modulo .
Input Format
Each test file contains multiple test cases. The first line contains an integer (), the number of test cases. For each test case:
- The first line contains an integer (), the number of nodes in the tree.
- The next lines each contain two integers and (), indicating an edge between node and node .
It is guaranteed that all given edges form a tree. It is also guaranteed that, for a single test file, the sum of all does not exceed .
Output Format
For each test case, output one integer per line: the number of good sets modulo .
3
3
1 2
2 3
7
1 4
5 3
2 4
1 6
4 3
3 7
10
1 5
5 2
2 10
5 8
1 4
5 6
4 3
2 7
9 5
1
9
45
Hint
For the first test case, the only possible that satisfy the first condition are and . Since in the maximum number of occurrences of any node as an endpoint is , while in it is , only is good.
Translated by ChatGPT 5