//yukicoder@cpp17 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using P = pair; const ll MOD = 998244353; const ll MODx = 1000000007; const int INF = (1<<30)-1; const ll LINF = (1LL<<62LL)-1; const double EPS = (1e-10); P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}}; P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}}; template vector make_vector(size_t a, T b) { return vector(a, b); } template auto make_vector(size_t a, Ts... ts) { return vector(a, make_vector(ts...)); } /* 確認ポイント cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる 計算量は変わらないが楽できるシリーズ min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる */ /* function corner below */ struct UnionFind { int n; vector par; vector size_; UnionFind(int n_) : n(n_), par((size_t)n_), size_((size_t)n_,1){ for(int i = 0; n > i; i++)par[i] = i; } int root(int x){ if(par[x] == x)return x; return par[x] = root(par[x]); } void unite(int a,int b){ int ra = root(a); int rb = root(b); if(ra==rb)return; if(size(ra) > size(rb)) swap(ra,rb); if(size(ra) == size(rb)){ par[max(ra,rb)] = min(ra,rb); if(ra > rb){ par[ra] = rb; size_[rb] += size_[ra]; }else{ par[rb] = ra; size_[ra] += size_[rb]; } }else{ par[ra] = rb; size_[rb] += size_[ra]; } } bool same(int a, int b){ return root(a) == root(b); } int size(int a){ return size_[root(a)]; } void debug(){ for(int i = 0; n > i; i++){ cout << size_[root(i)] << " "; } cout << endl; return; } }; /* Function corner above */ __attribute__((constructor)) void initial() { cin.tie(0); ios::sync_with_stdio(false); } int main(){ int n,m;cin>>n>>m; UnionFind t(n); for(int i = 0; m > i; i++){ int x,y;cin>>x>>y; t.unite(x-1,y-1); } for(int j = 0; n > j; j++){ cout << t.root(j)+1 << endl; } }