Given a directed graph with vertices and arcs, and two vertices and , is there a path that goes from to , passing through at least some other vertex at least twice? We will call this a looping path. Note that it can visit and only once (at the beginning and at the end).
Input consists of several cases, each with and , followed by pairs , with , indicating an arc from to , followed by and , with . Assume , , that vertices are numbered from 0 to , and that there are no repeated arcs.
For every graph, print “YES” if there is a looping path
from
to
,
and “NO” otherwise.
Author: Ángel García and Enrique Jiménez
Generation: 2026-01-25T10:35:39.300Z
© Jutge.org, 2006–2026.
https://jutge.org