PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#DSU0000070. Phá hủy đồ thị (Graph Destruction)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Phá hủy đồ thị (Graph Destruction)

Graph Destruction

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

An undirected simple graph contains NN vertices and MM edges. Vertices 1,2,…,N1,2,\ldots,N are erased in this order; erasing a vertex also removes every incident edge.

After vertices 11 through ii are gone, only vertices i+1,…,Ni+1,\ldots,N remain. Determine the number of connected components for each i=1,…,Ni=1,\ldots,N. An empty graph has zero components.

When vertex ii 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 NN has been deleted, the graph is empty and has 00 connected components.

Input

The first line contains N,MN,M. Each following line contains the endpoints Ai,BiA_i,B_i of an edge.

Output

Print NN lines; line ii is the component count after erasing vertices 11 through ii.

Subtasks

  • Subtask 1 (20 points): 1≤N≤301\le N\le 30; 0≤M≤1200\le M\le 120; 1≤Ai<Bi≤N1\le A_i<B_i\le N; edges are distinct and M≤N(N−1)/2M\le N(N-1)/2.
  • Subtask 2 (30 points): 1≤N≤30001\le N\le 3000; 0≤M≤60000\le M\le 6000; 1≤Ai<Bi≤N1\le A_i<B_i\le N; edges are distinct and M≤N(N−1)/2M\le N(N-1)/2.
  • Subtask 3 (50 points): 1≤N≤2000001\le N\le 200000; 0≤M≤2000000\le M\le 200000; 1≤Ai<Bi≤N1\le A_i<B_i\le N; edges are distinct and M≤N(N−1)/2M\le N(N-1)/2.

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 11, all remaining vertices are still connected. Deleting vertex 22 makes two components and deleting vertex 33 makes three. The later deletions leave two, one, and zero components respectively.