#P9871. H. HEX-A-GONE Trails
H. HEX-A-GONE Trails
H. HEX-A-GONE Trails
Problem Description
Consider a tree of nodes. Two OPs, OP I and OP II are playing a game on the tree. In the beginning, OP I and OP II are at node and node , respectively. Then they take turns to move, OP I moves first. In each move, a player at node must choose a neighboring node and move to . Remind that a player is not allowed to move to the other player's current position. After this move, node becomes invalid, meaning it cannot be moved to in the following moves of both players. If a player cannot make a valid move, he will lose the game. Please determine whether OP I has a strategy to make sure he will win.
Input
The input consists of multiple test cases. The first line contains a single integer () - the number of test cases. Description of the test cases follows. The first line of each test case contains one integer (). The second line contains two integers (, ). Each of the following lines contains two integers (, ) - an edge between . It's guaranteed that .
Output
For each test case, print a single integer - If OP I has a strategy to make sure he will win, output . Otherwise output .
Sample Input
3
5
2 3
2 5
5 4
5 1
3 4
5
3 5
2 4
1 5
4 3
1 4
5
1 2
3 4
4 2
5 1
4 5
Sample Output
1
1
0
Source
2023“钉耙编程”中国大学生算法设计超级联赛(7)