atcoder#AGC058F. [AGC058F] Authentic Tree DP
[AGC058F] Authentic Tree DP
Score : points
Problem Statement
For an undirected tree , let us define a rational number as follows.
- Let be the number of vertices in .
- If : Let .
- If :- For an edge in , we denote by and the two trees that result from deleting from (in arbitrary order).
- Let .
- For an edge in , we denote by and the two trees that result from deleting from (in arbitrary order).
- Let .
You are given a tree with vertices numbered to . The -th edge connects Vertex and Vertex .
Find the value .
What is a rational number $\text{mod }{998244353}$?
Under the Constraints of this problem, when the sought rational number is represented as , it can be proved that . Therefore, there is a unique integer such that $R \times Q \equiv P \pmod{998244353}, 0 \leq R < 998244353$. Find this .
Constraints
- The given graph is a tree.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
2
1 2
499122177
We have .
3
1 2
2 3
332748118
We have .
4
1 2
2 3
3 4
103983787
10
4 5
1 9
6 1
8 4
5 9
4 7
3 10
5 2
4 3
462781191