#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i)) #define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i)) #define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i)) #if defined(_MSC_VER) || __cplusplus > 199711L #define aut(r,v) auto r = (v) #else #define aut(r,v) __typeof(v) r = (v) #endif #define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it) #define all(o) (o).begin(), (o).end() #define pb(x) push_back(x) #define mp(x,y) make_pair((x),(y)) #define mset(m,v) memset(m,v,sizeof(m)) #define INF 0x3f3f3f3f #define INFL 0x3f3f3f3f3f3f3f3fLL using namespace std; typedef vector vi; typedef pair pii; typedef vector > vpii; typedef long long ll; template inline void amin(T &x, U y) { if(y < x) x = y; } template inline void amax(T &x, U y) { if(x < y) x = y; } void findCCs(int N, const vector > &edges, vector &counts) { vector deg(N + 1, 0); for(pii e : edges) ++ deg[e.first], ++ deg[e.second]; rep(i, N) deg[i + 1] += deg[i]; vector to(edges.size() * 2, -1); for(pii e : edges) { to[-- deg[e.first]] = e.second; to[-- deg[e.second]] = e.first; } counts.assign(N + 1, 0); vector vis(N, false); vector q(N); int t = 0; rep(s, N) if(!vis[s]) { int head = t; vis[s] = true; q[t ++] = s; for(int h = head; h < t; ++ h) { int i = q[h]; for(int j = deg[i]; j < deg[i + 1]; ++ j) { int k = to[j]; if(!vis[k]) { vis[k] = true; q[t ++] = k; } } } ++ counts[t - head]; } } void update(int *dp, int n, int s, int t) { for(int i = n; i >= 0; -- i) amin(dp[i + s], dp[i] + t); } int main() { int N; int M; while(~scanf("%d%d", &N, &M)) { vector > edges(M); rep(i, M) { int u; int v; scanf("%d%d", &u, &v), -- u, -- v; edges[i] = {u, v}; } vector counts; findCCs(N, edges, counts); vi dp(N + 1, INF); dp[0] = 0; int sum = 0; rer(i, 1, N) { int n = counts[i]; while(n > 0) { int m = (n + 1) / 2; update(&dp[0], sum, i * m, m); sum += i * m; n -= m; } } rer(i, 1, N) printf("%d\n", dp[i] == INF ? -1 : dp[i] - 1); } return 0; }