#include using namespace std; #define ALL(x) begin(x),end(x) #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<bool chmax(T &a,const T &b){if(abool chmin(T &a,const T &b){if(b ostream &operator<<(ostream &os,const vector&v){ for(int i=0;i<(int)v.size();i++) os< istream &operator>>(istream &is,vector&v){ for(T &x:v)is>>x; return is; } struct UnionFind{ int con; vector par,siz; UnionFind(int n):con(n),par(n),siz(n,1){ iota(begin(par),end(par),0); } int root(int x){ return (par[x]==x?x:(par[x]=root(par[x]))); } bool sameroot(int x,int y){ return root(x)==root(y); } bool unite(int x,int y){ x=root(x);y=root(y); if(x==y) return false; if(siz[x]>n>>m; vector> g(n); vector label(n),par(n); iota(ALL(label),0); iota(ALL(par),0); rep(i,n) g[i].push_back(i); rep(i,m){ int a,b;cin>>a>>b;a--,b--; a=par[a]; b=par[b]; if(a==b) continue; if(g[a].size()==g[b].size()){ if(label[a]>label[b]) swap(a,b); while(!g[b].empty()){ g[a].push_back(g[b].back()); par[g[b].back()]=a; g[b].pop_back(); } }else{ // a <- b if(g[a].size() ans(n); rep(i,n){ while(!g[i].empty()){ ans[g[i].back()]=label[i]; g[i].pop_back(); } } rep(i,n){ cout<