CF1830A.Copil Copac Draws Trees

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Copil Copac is given a list of n1n-1 edges describing a tree of nn vertices. He decides to draw it using the following algorithm:

  • Step 00 : Draws the first vertex (vertex 11 ). Go to step 11 .
  • Step 11 : For every edge in the input, in order: if the edge connects an already drawn vertex uu to an undrawn vertex vv , he will draw the undrawn vertex vv and the edge. After checking every edge, go to step 22 .
  • Step 22 : If all the vertices are drawn, terminate the algorithm. Else, go to step 11 .

The number of readings is defined as the number of times Copil Copac performs step 11 .

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 tt ( 1t1041 \leq t \leq 10^4 ) — the number of test cases. The description of test cases follows.

The first line of each test case contains a single integer nn ( 2n21052 \le n \le 2 \cdot 10^5 ) — the number of vertices of the tree.

The following n1n - 1 lines of each test case contain two integers uiu_i and viv_i ( 1ui,vin1 \le u_i, v_i \le n , uiviu_i \neq v_i ) — indicating that (ui,vi)(u_i,v_i) is the ii -th edge in the list. 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 21052 \cdot 10^5 .

输出格式

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 22 readings to draw the tree.

首页