CF2229E.Deconstruction Tree

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

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

  • let xx be the leaf with maximum index.
  • add xx into SS (note that if xx is already in SS then nothing changes).
  • select any leaf other than xx and remove it from the tree.

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

一棵包含 nn 个节点的树从天而降,同时还有一个初始为空的集合 SS。你欣喜若狂,于是执行以下操作 n−1n - 1 次:

  • 设 xx 为编号最大的叶子节点;
  • 将 xx 加入集合 SS(注意:若 xx 已在 SS 中,则不作任何改变);
  • 任选一个不同于 xx 的叶子节点,并将其从树中移除。

求你能得到的不同集合 SS 的数量。由于该数量可能极大,请对 998 244 353998\,244\,353 取模后输出。

输入格式

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

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

Then n−1n - 1 lines follow, each of which contain two integers uu and vv (1≤u,v≤n,u≠v1 \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.

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

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(2≤n≤2⋅1052 \le n \le 2 \cdot 10^5)—— 树的大小。

接下来是 n−1n - 1 行,每行包含两个整数 uu 和 vv(1≤u,v≤n,u≠v1 \le u,v \le n, u \ne v),表示由一条边连接的一对顶点。保证所给图是一棵树。

保证所有测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5。

输出格式

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

输出模 998 244 353998\,244\,353 意义下可得到的不同集合的数量。

输入输出样例

  • 输入#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

    输出#1

    1
    1
    3
    13
    1
    1

说明/提示

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

For the third testcase, the tree looks as follows:

you can make the sets:

  • 3,6,7{3, 6, 7} by removing in the order 1,2,3,4,5,61, 2, 3, 4, 5, 6
  • 3,4,6,7{3, 4, 6, 7} by removing in the order 2,1,3,4,5,62, 1, 3, 4, 5, 6
  • 3,4,5,6,7{3, 4, 5, 6, 7} by removing in the order 2,3,1,4,5,62, 3, 1, 4, 5, 6

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

对于第一个测试用例,只存在一种可能的删除顺序:11,从而得到集合 2{2}。

对于第三个测试用例,树的结构如下所示:

你可以通过以下删除顺序得到如下集合:

  • 按顺序 1,2,3,4,5,61, 2, 3, 4, 5, 6 删除,得到集合 3,6,7{3, 6, 7};
  • 按顺序 2,1,3,4,5,62, 1, 3, 4, 5, 6 删除,得到集合 3,4,6,7{3, 4, 6, 7};
  • 按顺序 2,3,1,4,5,62, 3, 1, 4, 5, 6 删除,得到集合 3,4,5,6,7{3, 4, 5, 6, 7}。

可以证明,这些是唯一可得到的集合。

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

首页