#include #include #include // #include #include #include #include using namespace std; typedef pair pii; struct UF{ vector par, cnt; explicit UF(int n) : par(n), cnt(n, 1) { iota(par.begin(), par.end(), 0); } int find(int x){ return x != par[x] ? par[x] = find(par[x]) : x; } bool unite(int x, int y){ x = find(x); y = find(y); if(x == y){ return false; } if(cnt[x] > cnt[y]){ swap(x, y); } par[x] = y; cnt[y] += cnt[x]; return true; } }; int main(){ int n, m; scanf("%d%d", &n, &m); UF uf(n + 1); for(int i = 0; i < m; ++i){ int u, v; scanf("%d%d", &u, &v); uf.unite(u, v); } vector com(n + 1); for(int i = 1; i <= n; ++i){ if(uf.find(i) == i){ ++com[uf.cnt[i]]; } } const int INF = 1010101010; vector dp1(n + 1, INF), dp2; dp1[0] = 0; vector buf(n + 9); for(int d = 1; d <= n; ++d){ int cnt = com[d]; if(!cnt){ continue; } dp2 = dp1; for(int r = 0; r < d; ++r){ int head = 0, tail = 0; for(int i = 0; i * d + r <= n; ++i){ int idx = i * d + r; if(head != tail && buf[head].second == i - cnt - 1){ ++head; } int val = dp1[idx] - i; while(head != tail && buf[tail - 1].first >= val){ --tail; } buf[tail++] = pii(val, i); dp2[idx] = min(dp2[idx], buf[head].first + i); } } dp1.swap(dp2); } for(int i = 1; i <= n; ++i){ printf("%d\n", dp1[i] == INF ? -1 : dp1[i] - 1); } }