#include #include #include #define rep(i, n) for(i = 0; i < n; i++) #define rrep(i, n) for(i = n - 1; i >= 0; i--) using namespace std; typedef pair P; void chmin(int &a, int b) { a = min(a, b); } struct UF { int par[100000]; int sz[100000]; UF() { for (int i = 0; i < 100000; i++) { par[i] = i; sz[i] = 1; } } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } void unit(int x, int y) { x = root(x); y = root(y); if (x != y) { par[x] = y; sz[y] += sz[x]; } } bool isRoot(int x) { return x == root(x); } int getSize(int x) { return sz[root(x)]; } }; int INF = 11451419; int n, m, u, v; UF uf; int cnt[100001]; vector

a; //a[i] = (num, cost) int dp[200001]; //dp([id])[sigma] = min_cnt int main() { int i, j; cin >> n >> m; rep(i, m) { cin >> u >> v; u--; v--; uf.unit(u, v); } rep(i, n) { if (uf.isRoot(i)) { cnt[uf.getSize(i)]++; } } rep(i, n + 1) { rep(j, 20) { if ((cnt[i] >> j) & 1) { a.push_back(P(i * (1 << j), (1 << j))); } } } rep(i, n + 1) dp[i] = INF; dp[0] = 0; rep(i, a.size()) { rrep(j, n + 1) { chmin(dp[j + a[i].first], dp[j] + a[i].second); } } rep(i, n) { if (dp[i + 1] >= INF) cout << -1 << endl; else cout << dp[i + 1] - 1 << endl; } return 0; }