#DSU0000070. Phá hủy đồ thị (Graph Destruction)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Phá hủy đồ thị (Graph Destruction)
Graph Destruction
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
An undirected simple graph contains vertices and edges. Vertices are erased in this order; erasing a vertex also removes every incident edge.
After vertices through are gone, only vertices remain. Determine the number of connected components for each . An empty graph has zero components.
When vertex is removed, only the remaining vertices and edges whose endpoints both remain are considered. A vertex with no incident edge still forms its own connected component.
Vertices are always deleted in increasing order. No vertex is restored and no new edge is added. Once vertex has been deleted, the graph is empty and has connected components.
Input
The first line contains . Each following line contains the endpoints of an edge.
Output
Print lines; line is the component count after erasing vertices through .
Subtasks
- Subtask 1 (20 points): ; ; ; edges are distinct and .
- Subtask 2 (30 points): ; ; ; edges are distinct and .
- Subtask 3 (50 points): ; ; ; edges are distinct and .
Examples
Input
6 7
1 2
1 4
1 5
2 4
2 3
3 5
3 6
Output
1
2
3
2
1
0
Explanation
After deleting vertex , all remaining vertices are still connected. Deleting vertex makes two components and deleting vertex makes three. The later deletions leave two, one, and zero components respectively.