Problem Statement
You a given a undirected forest graph (see definition below) with nodes and edges. Determine the number of trees in the forest graph.
NOTE: A forest graph is a graph containing multiple disconnected trees. Also think twice before starting to code.
Input Format
Your first line will contain two integers and . Your next lines will contain two integers each, and denoting that has an undirected edge to . You are guaranteed these edges will form a forest graph.
Output Format
Output a single integer, the number of trees of disconnected trees in the forest graph.
Constraints
- You are guaranteed there are no repeated edges.
- You are guaranteed the edges will form a forest graph.
Sample Cases
Input 1
5 3
0 1
1 2
3 4
Output 1
2
Notice there are two trees in this forest, one is formed by the nodes and the other by the nodes .
Input 2
10 6
7 0
1 4
0 1
1 2
1 3
7 8
Output 2
4
Here we can notice that a lot of the trees are single nodes, in particular nodes , and have no edges and are their own trees, all other nodes form a single tree.
Comments