CF1276D.Tree Elimination

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Vasya has a tree with nn vertices numbered from 11 to nn, and n−1n - 1 edges numbered from 11 to n−1n - 1. Initially each vertex contains a token with the number of the vertex written on it.

Vasya plays a game. He considers all edges of the tree by increasing of their indices. For every edge he acts as follows:

  • If both endpoints of the edge contain a token, remove a token from one of the endpoints and write down its number.
  • Otherwise, do nothing.

The result of the game is the sequence of numbers Vasya has written down. Note that there may be many possible resulting sequences depending on the choice of endpoints when tokens are removed.

Vasya has played for such a long time that he thinks he exhausted all possible resulting sequences he can obtain. He wants you to verify him by computing the number of distinct sequences modulo 998 244 353998\,244\,353.

瓦西娅有一棵包含 nn 个顶点的树,顶点编号为 11 到 nn,边编号为 11 到 n−1n - 1。初始时,每个顶点上均放置一个标记,其上写有该顶点的编号。

瓦西娅进行如下游戏:他按边编号从小到大的顺序依次考虑每条边。对每条边,他执行以下操作:

  • 若该边的两个端点上均存在标记,则从其中一个端点移除一个标记,并将该标记上的数字记录下来;
  • 否则,不进行任何操作。

游戏的结果即为瓦西娅所记录下的数字序列。注意:由于每次移除标记时可在两个端点中任选其一,因此可能得到多个不同的结果序列。

瓦西娅已长时间进行该游戏,以至于他认为自己已穷尽所有可能得到的结果序列。他希望你验证他的结论,即计算不同结果序列的总数(对 998 244 353998\,244\,353 取模)。

输入格式

The first line contains a single integer nn (2≤n≤2⋅1052 \leq n \leq 2 \cdot 10^5) — the number of vertices of the tree.

The next n−1n - 1 lines describe edges of the tree. The ii-th of these lines contains two integers ui,viu_i, v_i (1≤ui,vi≤n1 \leq u_i, v_i \leq n) — endpoints of the edge with index ii. It is guaranteed that the given graph is indeed a tree.

第一行包含一个整数 nn(2≤n≤2⋅1052 \leq n \leq 2 \cdot 10^5)——树的顶点数量。

接下来的 n−1n - 1 行描述树的边。其中第 ii 行包含两个整数 ui,viu_i, v_i(1≤ui,vi≤n1 \leq u_i, v_i \leq n)——编号为 ii 的边的两个端点。保证所给图确实是一棵树。

输出格式

Print a single integer — the number of distinct sequences modulo 998 244 353998\,244\,353.

输出一个整数——不同序列的数量对 998 244 353998\,244\,353 取模的结果。

输入输出样例

  • 输入#1

    5
    1 2
    1 3
    1 4
    1 5

    输出#1

    5
  • 输入#2

    7
    7 2
    7 6
    1 2
    7 5
    4 7
    3 5

    输出#2

    10

说明/提示

In the first sample case the distinct sequences are (1),(2,1),(2,3,1),(2,3,4,1),(2,3,4,5)(1), (2, 1), (2, 3, 1), (2, 3, 4, 1), (2, 3, 4, 5).

Int the second sample case the distinct sequences are (2,6,5,3),(2,6,5,7),(2,6,7,2),(2,6,7,5),(2,7,3),(2,7,5),(7,1,3),(7,1,5),(7,2,3),(7,2,5)(2, 6, 5, 3), (2, 6, 5, 7), (2, 6, 7, 2), (2, 6, 7, 5), (2, 7, 3), (2, 7, 5), (7, 1, 3), (7, 1, 5), (7, 2, 3), (7, 2, 5).

在第一个样例中,不同的序列有 (1),(2,1),(2,3,1),(2,3,4,1),(2,3,4,5)(1), (2, 1), (2, 3, 1), (2, 3, 4, 1), (2, 3, 4, 5)。

在第二个样例中,不同的序列有 (2,6,5,3),(2,6,5,7),(2,6,7,2),(2,6,7,5),(2,7,3),(2,7,5),(7,1,3),(7,1,5),(7,2,3),(7,2,5)(2, 6, 5, 3), (2, 6, 5, 7), (2, 6, 7, 2), (2, 6, 7, 5), (2, 7, 3), (2, 7, 5), (7, 1, 3), (7, 1, 5), (7, 2, 3), (7, 2, 5)。

输入解题思路,AI测评打分。不知道怎么写?

首页