Skip to content
CampusEduX

Connected Components

Easyjavapythonccppjavascript

Given an undirected graph, count how many connected components it has.

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 the number of connected components.

Related Problems

  • Graph Using Adjacency List
    Easy · java, python, c, cpp, javascript
    Solve Problem
  • BFS Traversal
    Easy · java, python, c, cpp, javascript
    Solve Problem
  • DFS Traversal
    Easy · java, python, c, cpp, javascript
    Solve Problem

Input (stdin)

Output

Run your code to see output here...