Looping path

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.

Problem information

Author: Ángel García and Enrique Jiménez

Generation: 2026-01-25T10:35:39.300Z

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