Please write a program to find out that whether a directed graph has cycles.
There are many cases in input.
The first line in the input contains three integers: n, m, representing the number of nodes in the graph and the number of edges in the graph.
The next m lines, each line contains 2 integers, u and v (1<= u, v <= n). That means there is an edge from u to v(v to u has no edge).
Input will be terminated by EOF (End-Of-File).
There has no node connected to itself!!
Problem size
1069: 1 <= n <= 10
1070: 1 <= n <= 100
1071: 1 <= n <= 1000
0 <= m <= n*(n-1)
Input 1: O(n!) can pass this
Input 2: O(n3) can pass this
Input 3: O(n2) can pass this
You can download the testdata and test your program, we do not use the same data to test your program.
For each case, print YES if there has at least one cycle in the graph, otherwise, print NO.