#include #include #include using namespace std; struct UnionFind{ vector parent; UnionFind(int n){ parent = vector(n, -1); } int root(int x){ if(parent[x] < 0) return x; else return parent[x] = root(parent[x]); } int count(int x){ return -parent[root(x)]; } bool same(int x, int y){ return root(x) == root(y); } void unite(int winner, int loser){ winner = root(winner); loser = root(loser); parent[winner] += parent[loser]; parent[loser] = winner; } }; int main(){ int n, m; cin >> n >> m; UnionFind data(n); auto winner = [&](int x, int y){ if(data.count(x) == data.count(y)) return min(x, y); else if(data.count(x) > data.count(y)) return x; else return y; }; for(int i = 0; i < m; i++){ int a, b; cin >> a >> b; a--; b--; a = data.root(a); b = data.root(b); if(data.same(a, b)) continue; int w = winner(a, b); int l = (w == a) ? b : a; data.unite(w, l); } for(int i = 0; i < n; i++) cout << data.root(i)+1 << endl; return 0; }