并查集模板
Code: #include<iostream> #include<cstring> #include<string> #include<algorithm> #include<cstdlib> #include<cstdio> using namespace std; int n,m,bz; int father[200001]; int find(int x) { if(x==father[x]) return x; return father[x]=find(father[x]); } void unnio(int x,int y) { father[y]=x; } inline int read() { bool f=0; int x=0; char c=getchar(); while(c<'0'||c>'9') { if(c=='-') f=!f; c=getchar(); } while(c>='0'&&c<='9') { x=x*10+c-'0'; c=getchar(); } return f?-x:x; } inline void write(int x) { if(x<0) { putchar('-'); write(-x); } else { if(x/10) write(x/10); putchar(x%10+'0'); } } int main() {