CF1830A.Copil Copac Draws Trees
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Copil Copac is given a list of n−1 edges describing a tree of n vertices. He decides to draw it using the following algorithm:
- Step 0 : Draws the first vertex (vertex 1 ). Go to step 1 .
- Step 1 : For every edge in the input, in order: if the edge connects an already drawn vertex u to an undrawn vertex v , he will draw the undrawn vertex v and the edge. After checking every edge, go to step 2 .
- Step 2 : If all the vertices are drawn, terminate the algorithm. Else, go to step 1 .
The number of readings is defined as the number of times Copil Copac performs step 1 .
Find the number of readings needed by Copil Copac to draw the tree.
输入格式
Each test contains multiple test cases. The first line of input contains a single integer t ( 1≤t≤104 ) — the number of test cases. The description of test cases follows.
The first line of each test case contains a single integer n ( 2≤n≤2⋅105 ) — the number of vertices of the tree.
The following n−1 lines of each test case contain two integers ui and vi ( 1≤ui,vi≤n , ui=vi ) — indicating that (ui,vi) is the i -th edge in the list. It is guaranteed that the given edges form a tree.
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105 .
输出格式
For each test case, output the number of readings Copil Copac needs to draw the tree.
输入输出样例
输入#1
2 6 4 5 1 3 1 2 3 4 1 6 7 5 6 2 4 2 7 1 3 1 2 4 5
输出#1
2 3
说明/提示
In the first test case:
After the first reading, the tree will look like this:
After the second reading:
Therefore, Copil Copac needs 2 readings to draw the tree.