#P3412. 仓鼠找sugar II

    ID: 2403 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>洛谷原创概率论,统计期望洛谷月赛

仓鼠找sugar II

Description

The little hamster and his buddy sugar live in an underground cave system. Each node is an integer between 1n1 \sim n. The cave system is a tree (each edge has length 11). On this day the hamster plans to go from his bedroom aa (arbitrary) to his buddy’s bedroom bb (also arbitrary) (note that aa may be equal to bb). 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 33 neighbors is 13\dfrac{1}{3}). Once he reaches bb, 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 998,244,353998,244,353.

Formally, it can be shown that the answer can be written as an irreducible fraction yx\dfrac{y}{x}, where x≢0(mod998,244,353)x \not\equiv 0 \pmod{998,244,353}. It can be shown that there exists a unique integer zz (0z<998,244,3530 \le z \lt 998,244,353) such that xzy(mod998,244,353)x z \equiv y \pmod{998,244,353}; you only need to output the value of zz.

The little hamster is so weak and always gets beaten by JOHNKRAM. Please help him!

Input Format

The first line contains a positive integer nn, the number of nodes in the tree.

The next n1n-1 lines each contain two positive integers uu and vv, indicating that there is an edge between nodes uu and vv.

Output Format

Output a single integer, the answer modulo 998,244,353998,244,353.

3
1 2
1 3

110916041

Hint

Sample explanation: the true expected value is 169\dfrac {16}{9}.

If aa is a leaf and bb is the root, then the expectation is E1=1\mathbb{E}_1=1. There are 22 cases.

If aa is the root and bb is a leaf, then $\displaystyle \mathbb{E}_2=\frac{1}{2}+\frac{3}{4}+\frac{5}{8}+\cdots=3$. There are 22 cases.

If a,ba,b are different leaves, then E3=E2+1=4\mathbb{E}_3=\mathbb{E}_2+1=4. There are 22 cases.

If a=ba=b, then E4=0\mathbb{E}_4=0. There are 33 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 110,916,041110,916,041.

For 30%30\% of the testdata, n5n\le 5.

For 50%50\% of the testdata, n5,000n\le 5,000.

For all testdata, n100,000n\le 100,000.

Statement fixed by @Starrykiller.\text{Statement fixed by @Starrykiller.}

Translated by ChatGPT 5