#abc306g. [abc306_g]Return to 1
[abc306_g]Return to 1
Problem Statement
We have a directed graph with vertices and edges. The vertices are numbered from through , and the -th edge goes from vertex to vertex .
You are currently at vertex . Determine if you can make the following move times to end up at vertex :
- choose an edge going from the vertex you are currently at, and move to the vertex that the edge points at.
Given test cases, solve each of them.
Constraints
- All input values are integers.
- The sum of over all test cases is at most .
- The sum of over all test cases is at most .
- If , then .
Input
The input is given from Standard Input in the following format. Here, denotes the -th test case.
Each test case is given in the following format.
Output
Print lines.
The -th line should contain Yes
if you can make the move described in the problem statement times to end up at vertex , and No
otherwise.
Sample Input 1
4
2 2
1 2
2 1
3 3
1 2
2 3
3 1
7 10
1 6
6 3
1 4
5 1
7 1
4 5
2 1
4 7
2 7
4 3
7 11
1 6
6 3
1 4
5 1
7 1
4 5
2 1
4 7
2 7
4 3
3 7
Sample Output 1
Yes
No
No
Yes
For the -st test case,
- You inevitably repeat visiting vertices $1 \\rightarrow 2 \\rightarrow 1 \\rightarrow \\dots$. Thus, you will end up at vertex after making the move times, so the answer is
Yes
.
For the -nd test case,
- You inevitably repeat visiting vertices $1 \\rightarrow 2 \\rightarrow 3 \\rightarrow 1 \\rightarrow \\dots$. Thus, you will end up at vertex after making the move times, so the answer is
No
.