QOJ.ac

QOJ

Limite de temps : 1.0 s Limite de mémoire : 1024 MB Points totaux : 100 Hackable ✓
Statistiques

给定一棵拥有 $n$ 个节点的无根树,你需要为每个节点分配一个互不相同的权值,这些权值构成一个 $1$ 到 $n$ 的排列。

对于任意一种权值分配方案,我们考虑该树的所有直径(即树中最长的简单路径)。在这些直径中,我们选择节点权值序列(将沿路径的节点权值按顺序排列并进行字典序比较)字典序最大的那条直径。

你的目标是在所有可能的分配方案中,最小化这个“字典序最大的直径”所对应的权值序列的字典序。

输入格式

输入包含多组测试数据。

输入的第一行包含一个整数 $T$ ($1 \le T \le 10^5$),表示数据组数。

对于每组数据:

  • 第一行包含一个整数 $n$ ($2 \le n \le 2 \cdot 10^5$),表示节点数量。
  • 接下来的 $n - 1$ 行,每行包含两个整数 $u, v$ ($1 \le u, v \le n$),表示树的一条边。

保证所有数据的 $\sum n \le 2 \cdot 10^5$。

输出格式

对于每组数据,输出一行若干个整数,表示可能达到的最小的“字典序最大的直径”的权值序列。

样例

输入样例 1

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

输出样例 1

3 4 5 1
3 4 2
3 4 5 6 1
2 3 4 5 6 1
3 4 5 6 7 8 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.