Connected Components Mapper
Connected Components Mapper
EasyGraphs57% accepted
Count the connected groups in an undirected graph and label the graph as sparse or clustered.
Approach
Read N nodes and M edges. Print the number of connected components in the graph. Nodes are labeled 0 to N-1 (0-indexed).
Input
6 3
1 2
2 3
4 5
Output
3
More Graphs problems
Browse all coding problems →solution.py
Loading editor...
Test 1
Test 2
Test 3
Press Run to test your custom input, or Submit to judge against all test cases.
Sign in to continue
Create a free account to run code, submit solutions and track progress.
- Free forever — no credit card
- 10+ languages with live execution
- Points, streaks & leaderboards