int getf(int x) { return x==f[x]?x:f[x]=getf(f[x]); } void merge(int x,int y) { x=getf(x),y=getf(y); if(x!=y) f[y]=x; }