问题 H: HEX-A-GONE Trails

内存限制:512 MB 时间限制:6 S
题面:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

Consider a tree of n 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 x and node y, respectively. Then they take turns to move, OP I moves first.

In each move, a player at node imust choose a neighboring node j and move to j. Remind that a player is not allowed to move to the other player's current position. After this move, node ii 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.

输入格式

The input consists of multiple test cases. The first line contains a single integer T (1T500) - the number of test cases. Description of the test cases follows.

The first line of each test case contains one integer n (1n10^5).

The second line contains two integers x,y (1x,ynx!=y).

Each of the following n - 1lines contains two integers u,v(1u,vnu!=v) - an edge between u,v.

It's guaranteed that n6×10^5.

 

输出格式

For each test case, print a single integer - If OP I has a strategy to make sure he will win, output 1. Otherwise output 0.

输入样例 复制

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

输出样例 复制

1
1
0

分类标签