QOJ.ac

QOJ

Límite de tiempo: 2.0 s Límite de memoria: 1024 MB Puntuación total: 100

#10268. 计数距离数组

Estadísticas

给定一棵包含 $N$ 个节点(编号为 $1$ 到 $N$)的树,以及一个节点子集 $S$,我们定义一个大小为 $N$ 的数组 $A$,其元素定义如下:

  • $A_i = \max_{x \in S} (\text{dist}(x, i))$。

其中,$\text{dist}(x, y)$ 表示树中 $x$ 和 $y$ 之间唯一最短路径上的边数。

共有 $2^N - 1$ 种非空子集 $S$。请计算在所有 $2^N - 1$ 种 $S$ 的选择中,可能产生的不同数组 $A$ 的数量。由于答案可能很大,请输出其对 $998244353$ 取模的结果。

输入格式

  • 第一行包含一个整数 $T$,表示测试用例的数量。
  • 每个测试用例包含多行输入:
    • 第一行包含 $N$,即树的节点数。
    • 接下来的 $N - 1$ 行,每行包含两个整数 $u$ 和 $v$,表示树中的一条边 $(u, v)$。

输出格式

对于每个测试用例,输出一行,表示在所有 $2^N - 1$ 个非空子集 $S$ 中,可能产生的不同数组 $A$ 的数量,结果对 $998244353$ 取模。

数据范围

  • $1 \le T \le 10^4$
  • $2 \le N \le 2 \cdot 10^5$
  • $1 \le u, v \le N$
  • $N - 1$ 条输入边构成一棵树。
  • 所有测试用例的 $N$ 之和不超过 $2 \cdot 10^5$。

样例

样例输入 1

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

样例输出 1

3
6
23

说明 1

测试用例 1:共有 3 种可能的子集 $S$。每种情况产生的结果如下:

  • $S = \{1\}$,数组 $A = [0, 1]$
  • $S = \{2\}$,数组 $A = [1, 0]$
  • $S = \{1, 2\}$,数组 $A = [1, 1]$

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.