1069 - Directed-graph (I)   

Description

Please write a program to find out that whether a directed graph has cycles.

Input

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.

140.114.86.238/DS/prob2.zip

Output

For each case, print YES if there has at least one cycle in the graph, otherwise, print NO.

Sample Input  Download

Sample Output  Download

Tags




Discuss