Codeforces Round 986 (Div. 2)
E
Alice's Adventures in the Rabbit Hole
Codeforces
2300
原题
← DF →
翻译中…

Alice is at the bottom of the rabbit hole! The rabbit hole can be modeled as a tree$^{\text{∗}}$ which has an exit at vertex $1$, and Alice starts at some vertex $v$. She wants to get out of the hole, but unfortunately, the Queen of Hearts has ordered her execution.

翻译中…

Each minute, a fair coin is flipped. If it lands heads, Alice gets to move to an adjacent vertex of her current location, and otherwise, the Queen of Hearts gets to pull Alice to an adjacent vertex of the Queen's choosing. If Alice ever ends up on any of the non-root leaves$^{\text{†}}$ of the tree, Alice loses.

翻译中…

Assuming both of them move optimally, compute the probability that Alice manages to escape for every single starting vertex $1\le v\le n$. Since these probabilities can be very small, output them modulo $998\,244\,353$.

翻译中…

Formally, let $M = 998\,244\,353$. It can be shown that the exact answer can be expressed as an irreducible fraction $\frac{p}{q}$, where $p$ and $q$ are integers and $q \not \equiv 0 \pmod{M}$. Output the integer equal to $p \cdot q^{-1} \bmod M$. In other words, output such an integer $x$ that $0 \le x \lt M$ and $x \cdot q \equiv p \pmod{M}$.

翻译中…

$^{\text{∗}}$A tree is a connected simple graph which has $n$ vertices and $n-1$ edges.$^{\text{†}}$A leaf is a vertex that is connected to exactly one edge.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The first line of each test case contains a single integer $n$ ($2\le n\le 2\cdot 10^5$) — the number of vertices in the tree.

翻译中…

The $i$-th of the next $n - 1$ lines contains two integers $x_i$ and $y_i$ ($1 \le x_i, y_i \le n$ and $x_i \neq y_i$) — the edges of the tree. It is guaranteed that the given edges form a tree.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$.

翻译中…

Output

翻译中…

For each test case, output $n$ integers on one line — the probabilities of Alice escaping starting from vertex $1, 2, \ldots, n$. Since these probabilities can be very small, output them modulo $998\,244\,353$.

翻译中…

Note

翻译中…

For the first test case:

翻译中…
  1. Alice escapes from the root (vertex $1$) by definition with probability $1$.
  2. Alice immediately loses from vertices $4$ and $5$ since they are leaves.
  3. From the other two vertices, Alice escapes with probability $\frac 12$ since the Queen will pull her to the leaves.
翻译中…

样例

Input #1
2
5
1 2
1 3
2 4
3 5
9
1 2
2 3
4 5
5 6
7 8
8 9
2 4
5 7
Output #1
1 499122177 499122177 0 0
1 499122177 0 332748118 166374059 0 443664157 720954255 0
InputCopy OutputCopy
题目信息
题号
2028E
时间限制
2 s
内存限制
256 MB
标签
组合数学
DFS 及类似
动态规划
博弈论
贪心
数学
概率论
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。