CF2165E.Rainbow Branch
NOI/NOI+/CTSC
通过率:0%
时间限制:3.00s
内存限制:1024MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Given a tree with n vertices, you need to assign a color to each edge. Define the inconvenience of an assignment as the maximum number of colors on the path between any two vertices.
You need to assign exactly k different colors (each color must appear at least once) to the edges while minimizing the inconvenience of the assignment.
Please calculate the minimum inconvenience for all k=1,2,…,n−1.
给定一棵包含 n 个顶点的树,你需要为每条边分配一种颜色。定义一个染色方案的不便度(inconvenience)为任意两个顶点之间路径上所出现的不同颜色数的最大值。
你需要恰好使用 k 种不同的颜色(每种颜色至少出现一次)为所有边染色,并使该染色方案的不便度最小化。
请对所有 k=1,2,…,n−1,计算对应的最小不便度。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of the input contains one positive integer n (3≤n≤3⋅105) — the number of vertices.
The next n−1 lines each contain two positive integers ui,vi (1≤ui,vi≤n) — indicating that there is an edge between vertices ui and vi.
It is guaranteed that the edges in the input form a tree.
It is guaranteed that the sum of n over all test cases does not exceed 3⋅105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
输入的第一行包含一个正整数 n(3≤n≤3⋅105)—— 表示顶点的数量。
接下来的 n−1 行每行包含两个正整数 ui,vi(1≤ui,vi≤n)—— 表示顶点 ui 与 vi 之间存在一条边。
保证输入中的边构成一棵树。
保证所有测试用例中 n 的总和不超过 3⋅105。
输出格式
For each test case, print a single line containing n−1 integers. The i-th integer represents the minimum inconvenience for k=i.
对于每个测试用例,输出一行包含 n−1 个整数。其中第 i 个整数表示当 k=i 时的最小不便值。
输入输出样例
输入#1
3 6 3 4 6 1 3 2 3 1 4 5 8 8 6 7 4 8 5 2 7 3 2 5 2 1 2 3 1 2 2 3
输出#1
1 2 2 3 4 1 2 2 2 3 4 5 1 2
说明/提示
In the first test case, possible solutions for k=1,2,…,n−1 are as follows:

在第一个测试用例中,k=1,2,…,n−1 的可能解如下所示:

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