Skip to content
CampusEduX

Detect Cycle in Undirected Graph

Mediumjavapythonccppjavascript

Given an undirected graph, determine whether it contains at least one cycle.

Input Format

The first line contains two integers V and E. Each of the next E lines contains an undirected edge u v.

Output Format

Print 1 if the graph contains a cycle, otherwise print 0.

Related Problems

  • Detect Cycle in Directed 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...