Looping path

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

Input

Input consists of several cases, each with n and m, followed by m pairs
u v, with u ≠ v, indicating an arc from u to v, followed by x and y,
with x ≠ y. Assume 2 ≤ n ≤ 10⁵, 0 ≤ m ≤ 5n, that vertices are numbered
from 0 to n − 1, and that there are no repeated arcs.

Output

For every graph, print “YES” if there is a looping path from x to y, 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
