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.
Example 1
Input
5 3 0 1 1 2 3 4
Output
2
Explanation: The groups are {0,1,2} and {3,4}.
- 1 <= V <= 100000
- 0 <= E <= 200000
- 0 <= u, v < V