#include using namespace std; #define rep(i,a,b) for(int i=a;i struct UF { int par[NV], cnt[NV]; UF() { rep(i, 0, NV) par[i] = i, cnt[i] = 1; } int operator[](int x) { return par[x] == x ? x : par[x] = operator[](par[x]); } void operator()(int x, int y) { // xをyにくっつける x = operator[](x); y = operator[](y); if (x != y) par[x] = y, cnt[y] += cnt[x]; } }; int N, M; UF<101010> uf; int dp[1010][101010]; //----------------------------------------------------------------------------------- int main() { cin >> N >> M; rep(i, 0, M) { int a, b; scanf("%d%d", &a, &b); a--; b--; uf(a, b); } map cnt; rep(i, 0, N) if (i == uf[i]) { //printf("<%d = %d>\n", i, uf.cnt[i]); cnt[uf.cnt[i]]++; } vector> items; for (auto p : cnt) { //printf("[%d %d]\n", p.first, p.second); for (int i = 1; i <= p.second; i *= 2) { int sm = i - 1; int j = min(p.second - sm, i); items.push_back({p.first * j, j}); if (p.second - sm < i) break; } } int n = items.size(); rep(i, 0, n + 1) rep(j, 0, N + 1) dp[i][j] = INF; dp[0][0] = 0; rep(i, 0, n) rep(j, 0, N + 1){ dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); if (j + items[i].first <= N) dp[i + 1][j + items[i].first] = min(dp[i + 1][j + items[i].first], dp[i][j] + items[i].second); } rep(j, 1, N + 1) { if (dp[n][j] == INF) printf("-1\n"); else printf("%d\n", dp[n][j] - 1); } }