Good Bye 2025
F
Conquer or of Forest
Codeforces
2200
原题
← EG →
翻译中…

Define the unique ornamental coloring of a rooted tree$^{\text{∗}}$ as the following vertex coloring:

翻译中…
  • A vertex $v$ is colored white if the number of vertices in the subtree$^{\text{†}}$ rooted at $v$ is even;
  • Otherwise, $v$ is colored black.
翻译中…

On his quest to conquer a forest of Christmas trees, Yuuki encountered an ornamentally colored tree $T$ with $n$ vertices labeled from $1$ to $n$, rooted at vertex $1$.

翻译中…

Yuuki considers the tree conquered if and only if at least one of the following conditions holds:

翻译中…
  • There are no white vertices in the tree, or
  • There exists some vertex $v$ such that all white vertices lie on the simple path from the root $1$ to $v$.
翻译中…

To conquer the tree, Yuuki can apply the following operation on $T$ an arbitrary number of times (possibly zero):

翻译中…
  • First, choose a vertex $w$ that is colored white and is not the root of $T$. Let $p_w$ be the parent of $w$.
  • Then, remove the edge connecting $p_w$ and $w$, and add an edge between any two vertices such that $T$ remains a tree.
  • Finally, recolor the vertices of $T$ such that it is ornamentally colored. Note that $T$ is always rooted at vertex $1$.
翻译中…

image A possible application of the operation in the first test case. The resulting tree is conquered since all white vertices lie on the path between vertices $1$ and $3$.

翻译中…

Compute the number of distinct$^{\text{‡}}$ conquered trees that Yuuki can construct by applying the above operation an arbitrary number of times on $T$. Since the answer may be large, output it modulo $998\,244\,353$.

翻译中…

Note that Yuuki cannot stop midway through an operation (in particular, he must recolor the tree before checking if it is conquered). Additionally, Yuuki is allowed to apply the operation even if the tree is already conquered.

翻译中…

$^{\text{∗}}$A tree is a connected graph without cycles. $^{\text{†}}$A subtree of vertex $v$ is the subgraph of $v$, all its descendants, and all the edges between them. $^{\text{‡}}$Two trees are considered distinct if and only if there exists a pair of vertices such that there is an edge between them in one of the trees, and not in the other.

翻译中…

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 $T$.

翻译中…

Then $n-1$ lines follow, the $i$-th line containing two integers $u_i$ and $v_i$ ($1\le u_i \lt v_i\le n$) — the two vertices that the $i$-th edge connects.

翻译中…

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 a single integer — the number of distinct conquered trees that can be constructed from $T$, modulo $998\,244\,353$.

翻译中…

Note

翻译中…

In the first test case, below are the four conquered trees that can be constructed and a sequence of operations that constructs each one.

翻译中…

ExplanationIllustration The operation is applied zero times. The given tree is already conquered since all white vertices lie on the simple path between vertices $1$ and $4$. image The first and only operation selects $w$ to be vertex $3$ ($p_w$ is vertex $1$) and draws an edge between vertices $2$ and $4$. The resulting tree is conquered since all white vertices lie on the simple path between vertices $1$ and $3$. image The first and only operation selects $w$ to be vertex $3$ ($p_w$ is vertex $1$) and draws an edge between vertices $2$ and $3$. The resulting tree is conquered since all white vertices lie on the simple path between vertices $1$ and $3$. image The first operation selects $w$ to be vertex $3$ ($p_w$ is vertex $1$) and draws an edge between vertices $2$ and $4$. The second operation selects $w$ to be vertex $4$ ($p_w$ is vertex $2$) and draws an edge between vertices $1$ and $4$. The resulting tree is conquered since all white vertices lie on the simple path between vertices $1$ and $4$. image

翻译中…

In the second test case, Yuuki cannot apply the operation on $T$ since there are no white vertices. Additionally, $T$ is already conquered since there are no white vertices. Thus, the answer is $1$.

翻译中…

样例

Input #1
5
4
1 2
1 3
3 4
5
1 2
1 3
1 4
1 5
5
1 2
2 3
1 4
4 5
6
1 2
2 3
2 4
2 6
5 6
11
2 10
6 8
1 6
3 7
5 11
5 8
5 9
4 7
6 7
2 6
Output #1
4
1
16
8
2048
InputCopy OutputCopy
题目信息
题号
2178F
所属比赛
时间限制
2 s
内存限制
512 MB
标签
组合数学
数学
树

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