#P14946. Bus Station

Bus Station

Problem Description

There is a tree with nn nodes. A subset SS 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 SS.
  • Among all sets that satisfy the first condition, the maximum number of times any node appears as an endpoint of a path in SS is minimized.

Count the number of good sets SS. Output the answer modulo 998244353998244353.

Input Format

Each test file contains multiple test cases. The first line contains an integer tt (1t21041 \leq t \leq 2\cdot 10^4), the number of test cases. For each test case:

  • The first line contains an integer nn (2n1052 \leq n \leq 10^5), the number of nodes in the tree.
  • The next n1n - 1 lines each contain two integers uu and vv (1u,vn1 \leq u, v \leq n), indicating an edge between node uu and node vv.

It is guaranteed that all given edges form a tree. It is also guaranteed that, for a single test file, the sum of all nn does not exceed 21052\cdot 10^5.

Output Format

For each test case, output one integer per line: the number of good sets SS modulo 998244353998244353.

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 SS that satisfy the first condition are {(1,2),(2,3)}\{(1, 2), (2, 3)\} and {(1,3)}\{(1, 3)\}. Since in {(1,3)}\{(1, 3)\} the maximum number of occurrences of any node as an endpoint is 11, while in {(1,2),(2,3)}\{(1, 2), (2, 3)\} it is 22, only {(1,3)}\{(1, 3)\} is good.

Translated by ChatGPT 5