280. Connected Components
EasyDFSUnion-Find
Print the number of connected components of the undirected graph.
Input format
Line 1: n m Next m lines: u v
Output format
The number of components.
Example 1
Input
5 3 1 2 2 3 4 5
Output
2
Example 2
Input
4 0
Output
4
Constraints
1 ≤ n ≤ 10⁵
Read input from standard input and print the answer to standard output. Your code is judged against 5 test cases, most of them hidden.
Loading the MyLoginn IDE…