#K39462. Cycle Detection in a Directed Graph
Cycle Detection in a Directed Graph
Cycle Detection in a Directed Graph
You are given a directed graph with (n) nodes (numbered from 0 to (n-1)) and (m) directed edges. Your task is to determine whether the graph contains a cycle. A cycle is a path that starts and ends at the same vertex and contains at least one edge. The graph is provided via standard input (stdin), and your program should output the result to standard output (stdout).
inputFormat
The first line contains two integers (n) and (m), representing the number of nodes and edges respectively. Each of the following (m) lines contains two integers (u) and (v), indicating a directed edge from node (u) to node (v).
outputFormat
Output (True) if the graph contains a cycle; otherwise, output (False).## sample
3 3
0 1
1 2
2 0
True