满配并查集

wenge

2020-02-12 22:21:36

Personal

```cpp int f[N],g[N]; int find(int x){ if(x==f[x])return x; return f[x]=find(f[x]); } void merge(int x,int y){ x=find(x),y=find(y); if(g[x]>g[y])swap(x,y); f[x]=y; g[y]+=g[x]; } ```