版本比较
并查集
正文
增加 8 行删除 8 行
29 行未改动3031323334343536373839404141424344454546474849505147484950515253545574 行未改动29 行未改动### 代码
这里的代码添加了所有优化
#### 普通代码(代码简短好写🪶)#### 普通代码(代码简短好写)
:::success[DSU - common]{open}
```cppconst int N = 1e3 + 5;
int n,m,fa[N],u,v,cnt;int n, m, fa[N], u, v, cnt;
int popu[N];//存集合大小
inline int find(int x){return x == fa[x] ? x : fa[x] = find(fa[x]);}inline int find (int x) { return x == fa[x] ? x : fa[x] = find(fa[x]);}
inline void unite(int x,int y){ int fx = find(x),fy = find(y); if(fx != fy){ if(popu[fx] >= popu[fy]) fa[fy] = fx,popu[fx] += popu[fy]; else fa[fx] = fy,popu[fy] += popu[fx];inline void unite (int x, int y) { int fx = find(x), fy = find(y); if (fx != fy) { if(popu[fx] >= popu[fy]) fa[fy] = fx, popu[fx] += popu[fy]; else fa[fx] = fy, popu[fy] += popu[fx]; }}```
74 行未改动