Spectral::Cup 2026 Round 2 (Codeforces Round 1100, Div. 1 + Div. 2)
E
解构树
Deconstruction Tree
Codeforces
2100
原题
← DF →

解构树AI (CI翻译)

A tree with $n$ nodes fell from the sky along with an initially empty set $S$. Ecstatic by this unlikely event, you do the following $n - 1$ times:

一棵包含 $n$ 个节点的树和一个初始为空的集合 $S$ 从天而降。你为这一罕见的事件感到欣喜,并执行以下操作 $n - 1$ 次:AI (CI翻译)

  • let $x$ be the leaf with maximum index.
  • add $x$ into $S$ (note that if $x$ is already in $S$ then nothing changes).
  • select any leaf other than $x$ and remove it from the tree.
  • 令 $x$ 为编号最大的叶子节点。
  • 将 $x$ 加入 $S$(注意,如果 $x$ 已经在 $S$ 中,则集合不会发生变化)。
  • 选择任意一个不同于 $x$ 的叶子节点,并将其从树中删除。
AI (CI翻译)

Determine the number of distinct sets $S$ you can make. As the number could be ginormous, output it modulo $998\,244\,353$.

求你能够得到的不同集合 $S$ 的数量。由于答案可能非常大,请将其对 $998\,244\,353$ 取模后输出。AI (CI翻译)

Input

输入格式

AI (CI翻译)

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.

每个测试包含多个测试用例。第一行包含测试用例的数量 $t$($1 \le t \le 10^4$)。接下来是各测试用例的描述。AI (CI翻译)

The first line of each testcase contains an integer $n$ ($2 \le n \le 2 \cdot 10^5$) — the size of the tree.

每个测试用例的第一行包含一个整数 $n$($2 \le n \le 2 \cdot 10^5$)——树的大小。AI (CI翻译)

Then $n - 1$ lines follow, each of which contain two integers $u$ and $v$ ($1 \le u,v \le n, u \ne v$), which describe a pair of vertices connected by an edge. It is guaranteed that the given graph is a tree.

接下来 $n - 1$ 行,每行包含两个整数 $u$ 和 $v$($1 \le u,v \le n, u \ne v$),表示一条连接两个顶点的边。保证给出的图是一棵树。AI (CI翻译)

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

保证所有测试用例的 $n$ 之和不超过 $2 \cdot 10^5$。AI (CI翻译)

Output

输出格式

AI (CI翻译)

Output the number of distinct sets that can be obtained modulo $998\,244\,353$.

输出能够得到的不同集合的数量,对 $998\,244\,353$ 取模。AI (CI翻译)

Note

说明

AI (CI翻译)

For the first testcase, there is only one possible order: $1$, making the set $\{2\}$

对于第一个测试用例,只有一种可能的操作顺序:$1$,得到集合 $\{2\}$。AI (CI翻译)

For the third testcase, the tree looks as follows:

对于第三个测试用例,树的结构如下:AI (CI翻译)

image

imageAI (CI翻译)

you can make the sets:

你可以得到以下集合:AI (CI翻译)

  • $\{3, 6, 7\}$ by removing in the order $1, 2, 3, 4, 5, 6$
  • $\{3, 4, 6, 7\}$ by removing in the order $2, 1, 3, 4, 5, 6$
  • $\{3, 4, 5, 6, 7\}$ by removing in the order $2, 3, 1, 4, 5, 6$
  • 按照 $1, 2, 3, 4, 5, 6$ 的顺序删除节点,可以得到 $\{3, 6, 7\}$。
  • 按照 $2, 1, 3, 4, 5, 6$ 的顺序删除节点,可以得到 $\{3, 4, 6, 7\}$。
  • 按照 $2, 3, 1, 4, 5, 6$ 的顺序删除节点,可以得到 $\{3, 4, 5, 6, 7\}$。
AI (CI翻译)

It can be proven that these are the only sets obtainable.

可以证明,这些就是所有能够得到的集合。AI (CI翻译)

样例

Input #1
6
2
1 2
5
5 1
5 3
5 4
5 2
7
7 6
7 4
5 7
1 6
2 4
3 5
10
10 9
10 8
10 7
10 6
9 5
8 4
7 3
6 2
5 1
4
2 4
3 1
1 4
4
1 4
2 3
3 4
Output #1
1
1
3
13
1
1
InputCopy OutputCopy
题目信息
题号
2229E
时间限制
2 s
内存限制
256 MB
标签
组合数学
数据结构
动态规划
图论
树

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