题目描述
Problem Statement
You are given a simple undirected graph with N vertices numbered 1 to N and M edges numbered 1 to M. Edge i connects vertex u_i and vertex v_i.
Find the number of connected components in this graph.
Input
The input is given from Standard Input in the following format:
N M
u_1 v_1
u_2 v_2
$\vdots$
u_M v_M
Output
Print the answer.
Constraints
- $1 \leq N \leq 100$
- $0 \leq M \leq \frac{N(N - 1)}{2}$
- $1 \leq u_i, v_i \leq N$
- The given graph is simple.
- All values in the input are integers.
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 1, 2, 3, and edges 1, 2;
- a subgraph formed from vertices 4, 5, and edge 3.
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
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分
样例输入
5 3
1 2
1 3
4 5
样例输出
2