Snakes and Graph

All submissions for this problem are available.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
There is a graph consisting of n nodes and m edges. There is a snake in each of its nodes. These snakes want to stage a coup against the mongoose who controls and puts restrictions on various aspects of their life. If there is an edge between some two nodes, then it means that the snakes in those nodes can talk with each other. The mongoose wants to protect himself against the coup. First, he calculates the degree of each node, i.e. the number of snakes a snake can talk to. He starts with an integer d = 0 and goes till d = n  1. At each such d, he will select the set of nodes that have their degree (the originally computed degree, because the mongoose doesn't like to compute the degree each time) less than or equal to d. He will remove all the edges whose one or both the endpoints belong to this set. The snakes want to find, for each d, the minimum number of edges (or communication channels) that they should add so that each of the snakes is able to talk to every other snake either directly via an edge or via other snakes indirectly.
Input
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of the each test case contains two space separated integers: n, m.
Each of the next m lines contain two space separated integers u_{i}, v_{i} denoting that there is an edge between nodes u_{i} and v_{i}.
Output
For each test case, output n space separated integers corresponding to answers for d = 0 to n  1.
Constraints
 1 ≤ T ≤ 3
 1 ≤ n ≤ 10^{5}
 0 ≤ m ≤ min(n * (n  1) / 2, 2 * 10^{5})
 1 ≤ u_{i}, v_{i}≤ n
 u_{i} ≠ v_{i}
 The graph doesn't have self loops and multi edges.
Example
Input 1 5 4 1 2 2 3 2 4 4 5 Output 0 3 4 4 4
Explanation
Example 1. The degree of the nodes are [1, 3, 1, 2, 1].
For d = 0, all the vertices and edges are the present in the graph. The snakes can talk to each other already, and there is no need to add more edges. So, the answer is zero for d = 0.
For d = 1, the chosen vertex set will be [1, 3, 5]. The set of edges that will be removed will be (1, 2), (2, 3) and (4, 5). Only the edge (2, 4) is remaining. Now, in order to talk with each other, at least 3 edges must be added. One way of doing this is to add the three edges removed.
For d = 2, the chosen vertex set will be [1, 3, 4, 5]. All the edges of the graph will be removed. Now, in order to talk with each other, at least 4 edges must be added to the graph.
For d = 3 and d = 4 also, all the edges will be removed, and at least 4 edges must be added to the graph in order for all the snakes to talk with each other.
Author:  admin2 
Tester:  kingofnumbers 
Editorial  https://discuss.codechef.com/problems/SNGRAPH 
Tags  admin2, dsu, graphtheory, medium, snckpb17 
Date Added:  31052017 
Time Limit:  2 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.5, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 