CF2165E.Rainbow Branch

NOI/NOI+/CTSC

通过率:0%

时间限制:3.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

Given a tree with nn 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 kk 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−1k=1,2,\ldots,n-1.

给定一棵包含 nn 个顶点的树,你需要为每条边分配一种颜色。定义一个染色方案的不便度(inconvenience)为任意两个顶点之间路径上所出现的不同颜色数的最大值。

你需要恰好使用 kk 种不同的颜色(每种颜色至少出现一次)为所有边染色,并使该染色方案的不便度最小化。

请对所有 k=1,2,…,n−1k = 1, 2, \ldots, n-1,计算对应的最小不便度。

输入格式

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 the input contains one positive integer nn (3≤n≤3⋅1053\le n\le3\cdot10^5) — the number of vertices.

The next n−1n-1 lines each contain two positive integers ui,viu_i,v_i (1≤ui,vi≤n1\le u_i,v_i\le n) — indicating that there is an edge between vertices uiu_i and viv_i.

It is guaranteed that the edges in the input form a tree.

It is guaranteed that the sum of nn over all test cases does not exceed 3⋅1053\cdot10^5.

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

输入的第一行包含一个正整数 nn(3≤n≤3⋅1053\le n\le3\cdot10^5)—— 表示顶点的数量。

接下来的 n−1n-1 行每行包含两个正整数 ui,viu_i, v_i(1≤ui,vi≤n1\le u_i,v_i\le n)—— 表示顶点 uiu_i 与 viv_i 之间存在一条边。

保证输入中的边构成一棵树。

保证所有测试用例中 nn 的总和不超过 3⋅1053\cdot10^5。

输出格式

For each test case, print a single line containing n−1n-1 integers. The ii-th integer represents the minimum inconvenience for k=ik=i.

对于每个测试用例,输出一行包含 n−1n-1 个整数。其中第 ii 个整数表示当 k=ik=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−1k=1,2,\ldots,n-1 are as follows:

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

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

首页