【模板】并查集
唔...有空补
1 #include<bits/stdc++.h> 2 using namespace std; 3 int find (int x){ 4 int r=x; 5 while (pre[r]!=r) { 6 r=pre[r]; 7 } 8 int i=x,j; 9 while (i!=r) { 10 j=pre[i]; 11 pre[i]=r; 12 i=j; 13 } 14 return r; 15 } 16 void join (int x,int y){ 17 int a=find(x); 18 int b=find(y); 19 if(a!=b){ 20 pre[a]=b; 21 } 22 } 23 int main(){ 24 25 return 0; 26 }
“胡须如草芥疯长,悲欢不过梦一场”