CF2222G.Statistics on Tree

入门

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Nanatsukaze - Aria

You are given a tree of nn vertices. We define the value of a pair (u,v)(u,v) (1uvn1\leq u\leq v\leq n) as the size of the largest component after removing all edges on the path from uu to vv in the original tree.

For every 1in1\leq i\leq n, you have to find the number of pairs (u,v)(u,v) satisfying that its value is ii.

Nanatsukaze - Aria

给你一棵包含 nn 个顶点的树。我们定义一对顶点 (u,v)(u,v)(其中 1uvn1\leq u\leq v\leq n)的为:在原树中删去从 uuvv 的路径上的所有边后,所得图中最大连通分量的大小。

对每个 1in1\leq i\leq n,你需要求出满足其值恰好为 ii 的顶点对 (u,v)(u,v) 的数量。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1t1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains a single integer nn (1n1051\leq n \leq 10^5) — the number of vertices.

Then n1n-1 lines follow, the ii-th line containing two integers uu and vv (1u,vn1\leq u,v\leq n) — the two vertices that the ii-th edge connects.

It is guaranteed that the given edges form a tree.

It is guaranteed that the sum of nn over all test cases does not exceed 51055\cdot 10^5.

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

每个测试用例的第一行包含一个整数 nn1n1051\leq n \leq 10^5)——顶点的数量。

接下来是 n1n-1 行,其中第 ii 行包含两个整数 uuvv1u,vn1\leq u,v\leq n)——表示第 ii 条边所连接的两个顶点。

保证给定的边构成一棵树。

保证所有测试用例的 nn 之和不超过 51055\cdot 10^5

输出格式

For each test case, output nn integers, the ii-th of which denotes the number of distinct pairs (u,v)(u,v) satisfying its value is ii.

对于每个测试用例,输出 nn 个整数,其中第 ii 个整数表示满足其值为 ii 的不同数对 (u,v)(u,v) 的数量。

输入输出样例

  • 输入#1

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

    输出#1

    1 
    1 2 
    1 2 3 
    1 3 2 4 
    0 0 6 4 5 
    0 4 5 5 3 4 7 
    0 0 12 4 3 5 4 8

说明/提示

In the first test case, the value of pair (1,1)(1, 1) is 11.

In the second test case, the values of pairs (1,1)(1, 1) and (2,2)(2, 2) are both 22, because no edges will be removed. The value of pair (1,2)(1, 2) is 11, because edge (1,2)(1, 2) is on the path from 11 to 22 in the tree, and after removing it, there will be 22 components left, which are 1{1} and 2{2}, and the size of the largest component is 11.

In the sixth test case, the value of pair (4,6)(4, 6) is 33, because edges (3,4)(3, 4), (2,3)(2, 3), and (2,6)(2, 6) are on the path from 44 to 66 in the tree, and after removing them, there will be 44 components left, which are 1,2,5{1, 2, 5}, 3,7{3, 7}, 4{4}, and 6{6}, and the size of the largest component is 33.

在第一个测试用例中,数对 (1,1)(1, 1) 的值为 11

在第二个测试用例中,数对 (1,1)(1, 1)(2,2)(2, 2) 的值均为 22,因为不会删除任何边。数对 (1,2)(1, 2) 的值为 11,因为在树中从节点 11 到节点 22 的路径上包含边 (1,2)(1, 2),删除该边后将剩下 22 个连通分量,即 {1}\{1\}{2}\{2\},其中最大连通分量的大小为 11

在第六个测试用例中,数对 (4,6)(4, 6) 的值为 33,因为在树中从节点 44 到节点 66 的路径上包含边 (3,4)(3, 4)(2,3)(2, 3)(2,6)(2, 6),删除这三条边后将剩下 44 个连通分量,即 {1,2,5}\{1, 2, 5\}{3,7}\{3, 7\}{4}\{4\}{6}\{6\},其中最大连通分量的大小为 33

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

首页