forestsize


Problem Statement

You a given a undirected forest graph (see definition below) with nn nodes and mm 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 nn and mm. Your next mm lines will contain two integers each, uu and vv denoting that uu has an undirected edge to vv. 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

  • 1≤n≤1051 \leq n \leq 10^5
  • 0≤m<n−10 \leq m \lt n - 1
  • 0≤u,v<n0 \leq u, v \lt n
  • 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 {0,1,2}\{0, 1, 2\} and the other by the nodes {3,4}\{3, 4\}.

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 55, 66 and 99 have no edges and are their own trees, all other nodes form a single tree.

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.