欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1873H.Mad City
Mad City
Marcel and Valeriu are in the mad city, which is represented by buildings with two-way roads between them.
Marcel and Valeriu start at buildings and respectively. Marcel wants to catch Valeriu, in other words, be in the same building as him or meet on the same road.
During each move, they choose to go to an adjacent building of their current one or stay in the same building. Because Valeriu knows Marcel so well, Valeriu can predict where Marcel will go in the next move. Valeriu can use this information to make his move. They start and end the move at the same time.
It is guaranteed that any pair of buildings is connected by some path and there is at most one road between any pair of buildings.
Assuming both players play optimally, answer if Valeriu has a strategy to indefinitely escape Marcel.
Input
The first line contains a single integer () — the number of test cases.
The first line of each test case contains three space-separated integers , , (; ) — the number of buildings (which equals the number of roads) and the starting buildings of Marcel and Valeriu.
The following lines each contain two integers , (, ) — there is a road between buildings and . There is at most one road between any unordered pair of buildings.
The sum of over all test cases does not exceed .
The roads are given that it is possible to get from any building to any other building going along the roads.
Output
For each test case output "YES" if Valeriu can escape Marcel forever and "NO" otherwise.
You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
Note
In the first test case the graph looks as follows:
Marcel starts at building , while Valeriu starts at building . Valeriu knows which way Marcel will move around the triangle, and he can simply always move in the same way to avoid Marcel forever.
In the second test case the graph looks as follows:
Marcel starts at building , while Valeriu starts at building . Marcel can go to building on his first move and win, since Valeriu must either go to building (then he meets Marcel on the road from to ) or stay at building (then he meets Marcel at building ). So there is no strategy for Valeriu to win.
Samples
6
3 2 1
2 1
3 2
1 3
4 1 4
1 4
1 2
1 3
2 3
4 1 2
1 2
2 3
2 4
3 4
7 1 1
4 1
2 1
5 3
4 6
4 2
7 5
3 4
8 5 3
8 3
5 1
2 6
6 8
1 2
4 8
5 7
6 7
10 6 1
1 2
4 3
5 8
7 8
10 4
1 9
2 4
8 1
6 2
3 1
YES
NO
YES
NO
NO
YES
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |