F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

I love playing games

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 569    Accepted Submission(s): 185


Problem Description
Alice and Bob play a game on an undirected graph $G$ consisting of $n$ vertices numbered $1$ to $n$, and $m$ 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.
 

Input
There is only one test case for this question.

The first line contains an integer $T (T<=10000)$ . Then $T$ test cases follow.

Each test case contains $m+2$ lines.

The first line contains two integers $n$ and $m$ $(n\le10^3)$ — 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\le x\le n, 1\le y\le 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 $10^5$ and the sum of $m$ over all test cases doesn't exceed $2*10^5$. 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.
 

Sample Input
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
 

Sample Output
1 1
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-11 20:18:01, Gzip enabled