Never trust Ivan (3)

Naiv and Uradiga are in different rooms of the same building. Naiv has
to prepare a surprise party for Uradiga in a room different from where
he is. To avoid Uradiga discovering his plan, Naiv must move through the
building without encountering him.

We can model the building as an undirected connected graph, where the
vertices represent rooms and the edges represent bidirectional
corridors. We can assume three things:

- At each instant in time, Uradiga randomly chooses between staying
  still in the room he is in, or moving to any adjacent room.

- At each instant in time, Naiv also can stay still or move to any
  adjacent room.

- Naiv moves through the ventilation ducts. Therefore, if Uradiga and
  Naiv cross paths on an edge, they cannot see each other. (They can
  only meet in vertices, not edges.)

Given the description of the building, the initial positions of Naiv and
Uradiga, and the party room, can Naiv plan a sequence of movements that
guarantees that he will reach the party room without being discovered?

Input

Input consists of several cases. Each case begins with the numbers of
vertices n, the number of edges m, and three different integers
representing the room of Naiv, the room of Uradiga, and the party room.
Follow m pairs x y, with x ≠ y, to indicate an edge between x and y.
Assume 3 ≤ n ≤ 10⁵, 2 ≤ m ≤ 5n, that the given graph is connected, that
the vertices are numbered from 1 to n, and that there are no repeated
edges.

Output

For every case, print “Yes” if Naiv can avoid being discovered, and “No”
otherwise.

Problem information

Author: Ivan Geffner

Generation: 2026-01-25T12:20:54.997Z

© Jutge.org, 2006–2026.
https://jutge.org
