#421. I love playing games
I love playing games
Description
Alice and Bob play a game on an undirected graph consisting of vertices numbered to , and edges.
Before the game starts, Alice is at vertex x, Bob is at vertex y. The game rules as follows:
- Alice goes first, then Bob. with moves alternating each turn.
- They try to get the vertex z. At the end of a turn, if Alice arrives but Bob does not, Alice wins; If Bob arrives but Alice does not, Bob wins; If both arrive or both fail to arrive, it will be considered a draw.
- In a move, the current player can choose not to move or move to a vertex adjacent to the current vertex, if there is an edge between the two vertex.
- The player cannot be on the same vertex at the same time except the start position and end position.
- Both of them play in the optimal way. (i.e If there is a strategy to win, win; if not, try to get to a draw)
Your task is to determine who wins if both of them choose the best operation in their rounds.
Format
Input
There is only one test case for this question.
The first line contains an integer . Then T test cases follow.
Each test case contains m+2 lines.
The first line contains two integers n and m — numbers of vertices and edges in graph respectively.
The second line contains three integers x,y and z — the initial position of Alice,the initial position of Bob and the end position of them.
The next m lines contain edges descriptions. Each line contains two integers x and y $(1 \leqslant x \leqslant n,1 \leqslant y \leqslant n)$— denoting that there is an undirected edge between the vertices numbered x and y.
It is guaranteed that the sum of n over all test cases doesn't exceed and the sum of m over all test cases doesn't exceed . The given graph may contain loops and multi-edges.
Output
Print T integer, for each case, determine who wins. Output
- an integer 1 if Alice wins.
- an integer 2 if draw. i.e no one wins.
- an integer 3 if Bob wins.
Samples
2
10 13
8 1 10
1 2
1 3
2 4
2 5
3 5
8 9
9 4
9 5
4 6
5 6
6 10
5 7
7 10
8 9
2 3 8
1 2
2 6
2 7
6 4
7 5
4 3
5 3
6 8
7 8
1
1