CF1873H.Mad City

普及+/提高

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Marcel and Valeriu are in the mad city, which is represented by nn buildings with nn two-way roads between them.

Marcel and Valeriu start at buildings aa and bb 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.

马塞尔和瓦莱里乌位于一座疯狂的城市中,该城市由 nn 座建筑以及它们之间 nn 条双向道路构成。

马塞尔和瓦莱里乌分别起始于建筑 aa 和 bb。马塞尔的目标是抓住瓦莱里乌,即:与瓦莱里乌处于同一座建筑,或在同一条道路上相遇。

在每一轮移动中,二人各自选择移动至当前所在建筑的一个相邻建筑,或停留在原地。由于瓦莱里乌对马塞尔极为了解,他能够准确预知马塞尔下一步将前往何处;瓦莱里乌可利用这一信息来决定自己的移动。二人在同一时刻开始并完成每一轮移动。

题目保证:任意两座建筑之间均存在某条路径相连,且任意两座建筑之间至多只有一条道路。

假设双方均采取最优策略,请判断瓦莱里乌是否存在一种策略,使其能够无限期地躲避马塞尔。

输入格式

The first line contains a single integer tt (1≤t≤10001 \leq t \leq 1000) — the number of test cases.

The first line of each test case contains three space-separated integers nn, aa, bb (3≤n≤2⋅1053 \leq n \leq 2 \cdot 10^5; 1≤a,b≤n1 \leq a, b \leq n) — the number of buildings (which equals the number of roads) and the starting buildings of Marcel and Valeriu.

The following nn lines each contain two integers uiu_i, viv_i (1≤ui,vi≤n1 \le u_i, v_i \le n, ui≠viu_i \neq v_i) — there is a road between buildings uiu_i and viv_i. There is at most one road between any unordered pair of buildings.

The sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

The roads are given that it is possible to get from any building to any other building going along the roads.

第一行包含一个整数 tt(1≤t≤10001 \leq t \leq 1000),表示测试用例的数量。

每个测试用例的第一行包含三个用空格分隔的整数 nn、aa、bb(3≤n≤2⋅1053 \leq n \leq 2 \cdot 10^5;1≤a,b≤n1 \leq a, b \leq n),分别表示建筑物的数量(等于道路的数量)以及 Marcel 和 Valeriu 的起始建筑物编号。

接下来的 nn 行,每行包含两个整数 uiu_i、viv_i(1≤ui,vi≤n1 \le u_i, v_i \le n,ui≠viu_i \neq v_i),表示建筑物 uiu_i 与 viv_i 之间有一条道路。任意一对无序建筑物之间至多只有一条道路。

所有测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5。

所给的道路保证任意两座建筑物之间均可通过道路相互到达。

输出格式

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).

对于每个测试用例,如果瓦莱里乌能够永远逃脱马塞尔,则输出 “YES”,否则输出 “NO”。

您可以以任意大小写形式输出答案(例如,字符串 “yEs”、“yes”、“Yes” 和 “YES” 均被视为肯定回答)。

输入输出样例

  • 输入#1

    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

    输出#1

    YES
    NO
    YES
    NO
    NO
    YES

说明/提示

In the first test case the graph looks as follows:

Marcel starts at building 22, while Valeriu starts at building 11. 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 11, while Valeriu starts at building 44. Marcel can go to building 44 on his first move and win, since Valeriu must either go to building 11 (then he meets Marcel on the road from 11 to 44) or stay at building 44 (then he meets Marcel at building 44). So there is no strategy for Valeriu to win.

在第一个测试用例中,图的结构如下:

马塞尔从建筑 22 出发,而瓦莱里乌从建筑 11 出发。瓦莱里乌知道马塞尔将如何沿三角形移动,因此他只需始终以相同方式移动,即可永远避开马塞尔。

在第二个测试用例中,图的结构如下:

马塞尔从建筑 11 出发,而瓦莱里乌从建筑 44 出发。马塞尔可在第一步就移动到建筑 44 并获胜,因为此时瓦莱里乌要么必须移动到建筑 11(这样他将在从 11 到 44 的路上与马塞尔相遇),要么必须停留在建筑 44(这样他将在建筑 44 与马塞尔相遇)。因此,瓦莱里乌不存在任何获胜策略。

输入解题思路,AI测评打分。不知道怎么写?

首页