QOJ.ac

QOJ

时间限制: 10 s 内存限制: 1024 MB 总分: 100

#5502. 炫目之山

统计

Bytelandshire 的最高峰是 Mount Stackframe,这是一座以绝美景色闻名的风景秀丽的山峰。在 Mount Stackframe 上有 $n$ 个游客避难所(编号从 $1$ 到 $n$),以及 $n-1$ 条连接两个避难所的路径。避难所 $1$ 位于山顶,已知从任何其他避难所出发,都有且仅有一条路径可以到达 $1$(前提是不走回头路)。位于山脚的避难所是那些仅与一条路径相连的避难所(避难所 $1$ 除外,不用说,即使它只与一条路径相连,它也不是山脚避难所)。传统的 Mount Stackframe 徒步旅行从某个山脚避难所开始,在山顶结束。

如果游客停在某个避难所 $x$ 并向下看,他们会看到若干个避难所——这些避难所正是那些从它们出发前往 $1$ 的路径必须经过 $x$ 的避难所。国家公园领导层的一个新想法是,在所有从 $x$ 可见的避难所数量(包括 $x$ 本身)恰好为 $d$ 的地方建立一个观景点。

请找出所有的 $d$ 值,使得无论游客从哪个山脚避难所出发,在从山脚徒步到山顶的过程中,都至少会经过一个观景点。

输入格式

第一行包含测试用例的数量 $z$ ($1 \le z \le 10\,000$)。接下来是各测试用例的描述。

每个测试用例的第一行包含一个整数 $n$ ($2 \le n \le 1\,000\,000$),表示避难所的数量。接下来的 $n-1$ 行,每行包含两个整数 $a_i$ 和 $b_i$ ($1 \le a_i, b_i \le n$),表示第 $i$ 条路径连接避难所 $a_i$ 和 $b_i$。路径不会在避难所之外相交。

所有测试用例中避难所的总数不超过 $3 \cdot 10^6$。

输出格式

对于每个测试用例,输出两行:第一行包含满足条件的 $d$ 值的数量,使得每位游客总是会经过一个观景点。第二行按升序输出这些 $d$ 值。

样例

输入 1

1
9
1 2
2 3
3 4
3 5
2 6
6 7
7 8
7 9

输出 1

4
1 3 8 9

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.