Never trust Ivan (4) P22024


Statement
 

pdf   zip

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 will move to a randomly chosen adjacent room. He cannot stay in the same room.

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

  • 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 nn, the number of edges mm, and three different integers representing the room of Naiv, the room of Uradiga, and the party room. Follow mm pairs xx yy, with xyx \ne y, to indicate an edge between xx and yy. Assume 3n1053 \le n \le 10^5, 2m5n2 \le m \le 5n, that the given graph is connected, that the vertices are numbered from 1 to nn, and that there are no repeated edges.

Output

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

Public test cases
  • Input

    4 4 1 3 2  1 2  2 3  3 4  4 1
    3 3 1 2 3  1 2  2 3  3 1
    5 5 1 2 5  1 2  2 3  3 4  4 5  5 1
    5 5 1 2 4  1 2  2 3  3 4  4 5  5 1
    

    Output

    yes
    no
    yes
    no
    
  • Information
    Author
    Ivan Geffner
    Language
    English
    Official solutions
    C++
    User solutions
    C++