Is it cyclic?

Write a program that, given a directed graph, determines whether the
graph has any cycle or not.

Input

Input consists of several cases. Every case begins with the number of
vertices n and the number of arcs m. Follow m pairs u, v, indicating
that there is an arc u → v, where u ≠ v. Assume 1 ≤ n ≤ 10⁴, 0 ≤ m ≤ 5n,
and that for every pair of vertices u and v there is at most one arc of
the kind u → v. Vertices are numbered from 0 to n − 1.

Output

For every case, print “yes” or “no” depending on whether the graph has
any cycle or not.

Problem information

Author: Unknown
Translator: Enric Rodríguez

Generation: 2026-01-25T22:00:33.743Z

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