#include #include using namespace std; using namespace atcoder; using ll=long long; using ld=long double; ld pie=3.141592653589793; ll inf=144499; ll mod=1000000007; struct unionfind { vectorpar,siz; unionfind(ll n): par(n,-1),siz(n,1){} ll root(ll x){ if (par[x]==-1) { return x; }else{ return par[x]=root(par[x]); } } bool issame(ll x,ll y){ return root(x)==root(y); } bool unite(ll x,ll y){ x=root(x); y=root(y); if (x==y) { return false; } if (siz[x]> n >> m; vectorr(n); for (ll i = 0; i < n; i++) { r[i]=i; } unionfind uf(n); for (ll i = 0; i < m; i++) { ll a,b; cin >> a >> b; a--,b--; if (uf.issame(a,b)) { continue; } if (uf.size(a)>uf.size(b)) { ll x=r[uf.root(a)]; uf.unite(a,b); r[uf.root(a)]=x; }else if (uf.size(b)>uf.size(a)) { ll x=r[uf.root(b)]; uf.unite(a,b); r[uf.root(b)]=x; }else{ if (r[uf.root(a)]