#abc284c. [abc284_c]Count Connected Components
[abc284_c]Count Connected Components
Problem Statement
You are given a simple undirected graph with vertices numbered to and edges numbered to . Edge connects vertex and vertex .
Find the number of connected components in this graph.
Notes
A simple undirected graph is a graph that is simple and has undirected edges.
A graph is simple if and only if it has no self-loop or multi-edge.
A subgraph of a graph is a graph formed from some of the vertices and edges of that graph.
A graph is connected if and only if one can travel between every pair of vertices via edges.
A connected component is a connected subgraph that is not part of any larger connected subgraph.
Constraints
- The given graph is simple.
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
5 3
1 2
1 3
4 5
Sample Output 1
2
The given graph contains the following two connected components:
- a subgraph formed from vertices , , , and edges , ;
- a subgraph formed from vertices , , and edge .
Sample Input 2
5 0
Sample Output 2
5
Sample Input 3
4 6
1 2
1 3
1 4
2 3
2 4
3 4
Sample Output 3
1