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 nn and the number of arcs mm of a graph GG. Follow mm pairs uu, vv, indicating that there is an arc uvu \rightarrow v in GG, with uvu \neq v. Assume 1n1041 \leq n \leq 10^{4}, 0m5n0 \leq m \leq 5n, and that for every pair of vertices uu and vv there is at most one arc of the kind uvu \rightarrow v. Vertices are numbered from 00 to n1n-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-25T11:17:49.335Z

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