11481 - Directed-graph   

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 two 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 
Input1: 1 <= n <= 10

Input2: 1 <= n <= 100 

Input3&Input4: 1 <= n <= 1000

0 <= m <= n*(n-1)

 

Input 1: O(n!) can pass this
Input 2: O(n^3) can pass this
Input 3&Input 4: O(n^2) can pass this 

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