Skip to content
CampusEduX

Detect Cycle in Directed Graph

Mediumjavapythonccppjavascript

Given a directed graph, determine whether it contains a directed cycle.

Input Format

The first line contains two integers V and E. Each of the next E lines contains a directed edge u v (from u to v).

Output Format

Print 1 if a directed cycle exists, otherwise print 0.

Related Problems

  • Detect Cycle in Undirected Graph
    Medium · java, python, c, cpp, javascript
    Solve Problem
  • Shortest Path in Unweighted Graph
    Medium · java, python, c, cpp, javascript
    Solve Problem
  • Topological Sort
    Medium · java, python, c, cpp, javascript
    Solve Problem

Input (stdin)

Output

Run your code to see output here...