CF1790F.Timofey and Black-White Tree
提高+/省选-
通过率:0%
时间限制:4.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Timofey came to a famous summer school and found a tree on n vertices. A tree is a connected undirected graph without cycles.
Every vertex of this tree, except c0, is colored white. The vertex c0 is colored black.
Timofey wants to color all the vertices of this tree in black. To do this, he performs n−1 operations. During the i-th operation, he selects the vertex ci, which is currently white, and paints it black.
Let's call the positivity of tree the minimum distance between all pairs of different black vertices in it. The distance between the vertices v and u is the number of edges on the path from v to u.
After each operation, Timofey wants to know the positivity of the current tree.
蒂莫费来到一所著名的暑期学校,发现了一棵包含 n 个顶点的树。树是一种无环的连通无向图。
该树的每个顶点(除 c0 外)均为白色,而顶点 c0 为黑色。
蒂莫费希望将树的所有顶点都染成黑色。为此,他执行 n−1 次操作。在第 i 次操作中,他选择一个当前为白色的顶点 ci,并将其染成黑色。
我们定义树的正性(positivity)为:当前所有不同黑色顶点对之间的最小距离。顶点 v 与 u 之间的距离定义为从 v 到 u 的路径上的边数。
每次操作后,蒂莫费都想得知当前树的正性。
输入格式
The first line contains the integer t (1≤t≤104) — the number of testcases.
The first line of each testcase contains the integers n,c0 (2≤n≤2⋅105, 1≤c0≤n) — the number of vertices in the tree and index of the initial black vertex.
The second line of each testcase contains n−1 unique integers c1,c2,…,cn−1 (1≤ci≤n, ci=c0), where ci is the vertex which is colored black during the i-th operation.
Each of the next n−1 row of each testcase contains the integers vi,ui (1≤vi,ui≤n) — edges in the tree.
It is guaranteed that the sum of n for all testcases does not exceed 2⋅105.
第一行包含整数 t(1≤t≤104)——测试用例的数量。
每个测试用例的第一行包含两个整数 n,c0(2≤n≤2⋅105,1≤c0≤n)——树中顶点的数量以及初始黑色顶点的编号。
每个测试用例的第二行包含 n−1 个互不相同的整数 c1,c2,…,cn−1(1≤ci≤n,且 ci=c0),其中 ci 表示在第 i 次操作中被染成黑色的顶点。
每个测试用例接下来的 n−1 行,每行包含两个整数 vi,ui(1≤vi,ui≤n)——树中的边。
保证所有测试用例的 n 之和不超过 2⋅105。
输出格式
For each testcase, print n−1 integer on a separate line.
The integer with index i must be equal to positivity of the tree obtained by the first i operations.
对于每个测试用例,输出 n−1 个整数,每个整数占一行。
索引为 i 的整数必须等于执行前 i 个操作后所得树的“正性”(positivity)。
输入输出样例
输入#1
6 6 6 4 1 3 5 2 2 4 6 5 5 3 3 4 1 3 4 2 4 1 3 3 1 2 3 1 4 10 3 10 7 6 5 2 9 8 1 4 1 2 1 3 4 5 4 3 6 4 8 7 9 8 10 8 1 8 7 3 7 5 1 2 4 6 1 2 3 2 4 5 3 4 6 5 7 6 9 7 9 3 1 4 2 6 8 5 4 1 8 9 4 8 2 6 7 3 2 4 3 5 5 4 10 2 1 8 5 10 6 9 4 3 7 10 7 7 8 3 6 9 7 7 6 4 2 1 6 7 5 9 2
输出#1
3 2 1 1 1 3 1 1 3 2 2 2 2 2 1 1 1 4 2 2 1 1 1 5 1 1 1 1 1 1 1 4 3 2 2 1 1 1 1 1
说明/提示
In the first testcase, after the second operation, the tree looks like this: 
The distance between vertices 1 and 6 is 3, the distance between vertices 4 and 6 is 3, the distance between vertices 1 and 4 is 2. The positivity of this tree is equal to the minimum of these distances. It equals 2.
In the third testcase, after the fourth operation, the tree looks like this: 
The positivity of this tree is 2.
在第一个测试用例中,执行第二次操作后,树的结构如下:
顶点 1 与顶点 6 之间的距离为 3,顶点 4 与顶点 6 之间的距离为 3,顶点 1 与顶点 4 之间的距离为 2。该树的“正性”(positivity)定义为上述所有距离中的最小值,即 2。
在第三个测试用例中,执行第四次操作后,树的结构如下:
该树的“正性”为 2。
输入解题思路,AI测评打分。不知道怎么写?