标准并差集
int f[10005]; int get(int n) { if(f[n]==n)return n; else return f[n]=get(f[n]); } void merget(int x,int y) { f[get(x)]=get(y); }