#P3412. 仓鼠找sugar II
仓鼠找sugar II
Description
The little hamster and his buddy sugar live in an underground cave system. Each node is an integer between . The cave system is a tree (each edge has length ). On this day the hamster plans to go from his bedroom (arbitrary) to his buddy’s bedroom (also arbitrary) (note that may be equal to ). However, after studying OI too hard, he has gone silly and does not know how to take the shortest path, so he just walks randomly. When he is at a node, he moves with equal probability to its parent or any of its children (for example, if this node has one parent and two children, then the probability of moving to each of these neighbors is ). Once he reaches , he stops.
Now the little hamster wants to know the expected number of steps when he reaches the destination. This expectation is a rational number. To avoid precision errors, we ask you to output this rational number modulo .
Formally, it can be shown that the answer can be written as an irreducible fraction , where . It can be shown that there exists a unique integer () such that ; you only need to output the value of .
The little hamster is so weak and always gets beaten by JOHNKRAM. Please help him!
Input Format
The first line contains a positive integer , the number of nodes in the tree.
The next lines each contain two positive integers and , indicating that there is an edge between nodes and .
Output Format
Output a single integer, the answer modulo .
3
1 2
1 3
110916041
Hint
Sample explanation: the true expected value is .
If is a leaf and is the root, then the expectation is . There are cases.
If is the root and is a leaf, then $\displaystyle \mathbb{E}_2=\frac{1}{2}+\frac{3}{4}+\frac{5}{8}+\cdots=3$. There are cases.
If are different leaves, then . There are cases.
If , then . There are cases.
So the answer is $\displaystyle \frac{2\times 1+2\times 3+2\times 4+3\times 0}{2+2+2+3}=\frac{16}{9}$.
Since $110,916,041\times 9=998,244,369\equiv 16\pmod {998,244,353}$, output .
For of the testdata, .
For of the testdata, .
For all testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号