Loading repovive.com/problems/classics/12
Given an undirected graph with n vertices and m edges, find the number of connected components.
A connected component is a maximal set of vertices such that there is a path between every pair of vertices in the set.
number of connected components
5 3 1 2 2 3 4 5
For this input, the required output is 2.
2
4 4 1 2 2 3 3 4 4 1
For this input, the required output is 1.
1
5 0
For this input, the required output is 5.
5