#include using namespace std; #define rep(i,a,b) for(int i=a;i par; // 親ノード vector rank; // ランク vector size; UnionFind(int n = 1) { init(n); } void init(int n = 1) { par.resize(n); rank.resize(n); size.resize(n); for (int i = 0; i < n; ++i) { par[i] = i, rank[i] = 0; size[i] = 1; } } int root(int x) { if (par[x] == x) { return x; } else { int r = root(par[x]); return par[x] = r; } } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (size[x] < size[y]) swap(x, y); if(size[x] == size[y]){ if(x > y) swap(x,y); } par[y] = x; size[x] += size[y]; return true; } int getsize(int x){ return size[x]; } }; signed main(){ std::ios::sync_with_stdio(false); std::cin.tie(0); int n,m; cin >> n >> m; UnionFind uf = UnionFind(n); rep(i,0,m){ int a,b; cin >> a >> b; uf.merge(a-1,b-1); } rep(i,0,n){ cout << uf.root(i)+1 << endl; } }