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 . Follow pairs , , indicating that there is an arc , where . 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.
Input
3 2 0 1 1 2 3 3 0 1 1 2 2 0 4 5 2 3 1 3 3 0 0 2 0 1 5 6 0 1 0 2 0 3 1 3 2 3 4 1
Output
no yes yes no