#abc306g. G - Return to 1
G - Return to 1
Score : points
问题描述
我们有一个有向图,包含 个顶点和 条边。顶点从 到 编号,第 条边从顶点 指向顶点 。
你现在位于顶点 。判断你是否能够执行以下操作 次,并最终回到顶点 :
- 从当前所在的顶点选择一条出发的边,并沿着这条边移动到它所指向的顶点。
给定 组测试用例,请分别解决每组问题。
以上为通义千问 qwen-max 翻译,仅供参考。
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 . 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
.
update @ 2024/3/10 08:39:51