#include #include #include #include #define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i)) #ifndef __GNUC__ #include #endif using namespace std; struct UnionFind { vector data; void init(int n) { data.assign(n, -1); } bool unionSet(int x, int y) { x = root(x); y = root(y); if(x != y) { if(data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; } return x != y; } bool findSet(int x, int y) { return root(x) == root(y); } int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); } int size(int x) { return -data[root(x)]; } }; void update(int *dp, int n, int s, int t) { assert(s > 1); if(n % 2 == 0) { int &x = dp[n + s], y = dp[n] + t; if(x > y) x = y; if(-- n < 0) return; } #ifndef __GNUC__ const __m128i tttt = _mm_set1_epi32(t); for(int i = n - 1; i >= 0; i -= 2) { const __m128i x = _mm_loadu_si128(reinterpret_cast(dp + (i + s))); const __m128i y = _mm_add_epi32(_mm_loadu_si128(reinterpret_cast(dp + i)), tttt); const __m128i z = _mm_min_epi32(x, y); _mm_storeu_si128(reinterpret_cast<__m128i*>(dp + (i + s)), z); } #else __asm("vmovd %0, %%xmm2\n\tvpshufd $0, %%xmm2, %%xmm1":: "r"(t) : "xmm1", "xmm2"); for(int i = n - 1; i >= 0; i -= 2) { const int * const p = dp + i; int * const q = dp + (i + s); __asm("vpaddd %1, %%xmm1, %%xmm0\n\tvpminsd %0, %%xmm0, %%xmm0\n\tvmovups %%xmm0, %0" : "=m"(*q) : "m"(*p) : "xmm0", "xmm1"); } #endif } int main() { int N; int M; while(~scanf("%d%d", &N, &M)) { UnionFind uf; uf.init(N); rep(i, M) { int u; int v; scanf("%d%d", &u, &v), -- u, -- v; uf.unionSet(u, v); } vector counts(N + 1); rep(i, N) if(uf.root(i) == i) ++ counts[uf.size(i)]; const int INF = 0x3f3f3f3f; vector dp(N + 1, INF); for(int n = counts[1]; n >= 0; -- n) dp[n] = n; int sum = counts[1]; for(int i = 2; i <= N; ++ i) { int n = counts[i]; while(n > 0) { int m = (n + 1) / 2; update(&dp[0], sum, i * m, m); sum += i * m; n -= m; } } for(int i = 1; i <= N; ++ i) printf("%d\n", dp[i] == INF ? -1 : dp[i] - 1); } return 0; }