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

#DSU0000071. Tập đỉnh có thể đến (Reachable Set)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Tập đỉnh có thể đến (Reachable Set)

Reachable Set

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

You are given an undirected simple graph with NN vertices and MM edges. Independently for each k=1,…,Nk=1,\ldots,N, you may erase vertices and their incident edges. Decide whether the vertices reachable from vertex 11 can be made exactly {1,2,…,k}\{1,2,\ldots,k\}.

Vertices required to remain reachable cannot be erased. If the target reachable set is achievable, minimize the number of deleted vertices. Each value of kk starts with the original graph.

Each operation deletes one vertex together with all its incident edges; no edge can be added. To obtain exactly the reachable set {1,2,…,k}\{1,2,\ldots,k\} from vertex 11, every vertex in that set must remain and must be reachable from vertex 11.

Vertices with labels greater than kk do not all have to be deleted: any such vertex that is unreachable from vertex 11 may remain. Conversely, if deleting vertices cannot make all of 1,…,k1,\ldots,k reachable without including any other vertex, output -1. Each value of kk starts from the original graph.

Input

The first line contains N,MN,M, followed by MM lines describing edges ui,viu_i,v_i.

Output

Print NN lines. Line kk contains the minimum number of deletions, or -1 if the reachable set cannot be exactly {1,…,k}\{1,\ldots,k\}.

Subtasks

  • Subtask 1 (20 points): 1≤N≤301\le N\le 30; 0≤M≤1200\le M\le 120; 1≤ui<vi≤N1\le u_i<v_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≤ui<vi≤N1\le u_i<v_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≤3000000\le M\le 300000; 1≤ui<vi≤N1\le u_i<v_i\le N; edges are distinct and M≤N(N−1)/2M\le N(N-1)/2.

Examples

Input

6 7
1 2
1 5
2 3
2 4
2 5
3 6
5 6

Output

2
3
3
2
1
0

Explanation

For k=2k=2, vertices 3,4,53,4,5 must be deleted to make precisely 1,21,2 reachable from vertex 11, so the answer is 33. The answers for the other values of kk are 2,3,2,1,02,3,2,1,0 in order. For k=6k=6, no deletion is necessary because every vertex is already reachable from vertex 11.