Components over Time
Edges arrive one by one on N initially-isolated nodes. After EACH edge, print the number of connected components.
Input: the first line has N and M; each of the next M lines has an edge u v.
Output: M lines: the component count after each edge.
Constraints:
- 1 ≤ N, M ≤ 105
Sample Tests
Input 1
4 3 1 2 3 4 2 3
Output 1
3 2 1
Input 2
2 2 1 1 1 2
Output 2
2 1
Discussion (opens after you solve — no spoilers before)
No comments yet.