Problem8607--GRL_4_A : Cycle Detection for a Directed Graph

8607: GRL_4_A : Cycle Detection for a Directed Graph

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 256 MiB

Description

Find a cycle in a directed graph G(V,E).

Input

In the first line, two integers |V| is the number of vertices and |E| is the number of edges in the graph. The graph vertices are named with the numbers 0, 1,..., |V|-1 respectively.

In the following |E| lines, two integers $s_i$ and $t_i$ represent source and target verticess of i-th edge (directed).

Output

Print 1 if G has cycle(s), 0 otherwise.

Constraints

$1 ≤ |V| ≤ 100$
$0 ≤ |E| ≤ 1,000$
$s_i ≠ t_i$

Sample 1 Input

3 3
0 1
0 2
1 2

Sample 1 Output

0

Sample 2 Input

3 3
0 1
1 2
2 0

Sample 2 Output

1

HINT

相同题目:GRL_4_A

Source/Category