Write a program that, given a directed graph, determines whether the graph has any cycle or not.
Input consists of several cases. Every case begins with the number of vertices and the number of arcs of a graph . Follow pairs , , indicating that there is an arc in , with . Assume , , and that for every pair of vertices and there is at most one arc of the kind . Vertices are numbered from to .
For every case, print “yes” or “no” depending on whether the graph has any cycle or not.
Author: Unknown
Translator: Enric Rodríguez
Generation: 2026-01-25T11:17:49.335Z
© Jutge.org, 2006–2026.
https://jutge.org