创建于 2026/07/18 · 更新于 2026/07/18
LP and Rifleman are playing a game.
Initially, there is an unrooted tree with vertices.
Two players, LP and Rifleman, play alternately. LP moves first.
1. LP chooses a vertex whose degree is not equal to 2 and removes it, or she may do nothing.
2. Then Rifleman chooses two vertices that are not connected (i.e., belong to different connected components) and adds an edge between them.
If after a non-zero number of operations , the graph becomes connected again, the game ends immediately.
LP wants to minimize the number of remaining vertices, Rifleman wants to maximize it. Determine the final number of vertices when both play optimally.
The first line contains the number of testcases .
For each testcase, the first line contains the number of vertices .
Each for the next lines contains two integers and ,meaning that there is an edge between vertex and .
For each testcase,you need to print the final number of vertices in a single line.
2
4
1 2
1 3
1 4
4
1 2
2 3
3 4
2
3
2
7
1 2
1 3
2 4
2 5
3 6
3 7
12
1 2
1 3
1 4
1 5
2 6
2 7
2 8
2 9
3 10
3 11
3 12
3
4