#P1975D. Paint the Tree
Paint the Tree
No submission language available for this problem.
Description
378QAQ has a tree with vertices. Initially, all vertices are white.
There are two chess pieces called and on the tree. and are initially located on vertices and respectively. In one step, 378QAQ will do the following in order:
- Move to a neighboring vertex. If the target vertex is white, this vertex will be painted red.
- Move to a neighboring vertex. If the target vertex is colored in red, this vertex will be painted blue.
Initially, the vertex is painted red. If , the vertex is painted blue instead. Note that both the chess pieces must be moved in each step. Two pieces can be on the same vertex at any given time.
378QAQ wants to know the minimum number of steps to paint all vertices blue.
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains one integer ().
The second line of each test case contains two integers and ().
Then lines follow, each line contains two integers and (), indicating an edge between vertices and . It is guaranteed that these edges form a tree.
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, output the minimum number of steps to paint all vertices blue.
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains one integer ().
The second line of each test case contains two integers and ().
Then lines follow, each line contains two integers and (), indicating an edge between vertices and . It is guaranteed that these edges form a tree.
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, output the minimum number of steps to paint all vertices blue.
Note
In the first test case, 378QAQ can paint all vertices blue in the following order:
- Initially, is located on the vertex , and is located on the vertex . The vertex is painted red and the vertex is white.
- 378QAQ moves to the vertex and paints it red. Then 378QAQ moves to the vertex and paints it blue.
- 378QAQ moves to the vertex . Then 378QAQ moves to the vertex and paints it blue.