Looping path P28620


Statement
 

pdf   zip

Given a directed graph with nn vertices and mm arcs, and two vertices xx and yy, is there a path that goes from xx to yy, passing through at least some other vertex at least twice? We will call this a looping path. Note that it can visit xx and yy only once (at the beginning and at the end).

Input

Input consists of several cases, each with nn and mm, followed by mm pairs uu vv, with uvu \ne v, indicating an arc from uu to vv, followed by xx and yy, with xyx \ne y. Assume 2n1052 \le n \le 10^5, 0m5n0 \le m \le 5n, that vertices are numbered from 0 to n1n-1, and that there are no repeated arcs.

Output

For every graph, print “YES” if there is a looping path from xx to yy, and “NO” otherwise.

Public test cases
  • Input

    3 3
    0 2  2 0  2 1
    0 1
    
    4 3
    1 3  0 1  3 1
    0 2
    
    4 4
    3 2  1 3  0 1  3 1
    0 2
    
    4 4
    1 2  1 3  0 1  3 1
    0 2
    

    Output

    NO
    NO
    YES
    YES
    
  • Information
    Author
    Ángel García and Enrique Jiménez
    Language
    English
    Official solutions
    C++
    User solutions
    C++