版本比较
并查集
正文
增加 8 行删除 8 行
29 行未改动303132333435363738394041424344454647484950515253545574 行未改动29 行未改动### 代码这里的代码添加了所有优化#### 普通代码(代码简短好写🪶):::success[DSU - common]{open}```cppconst int N = 1e3 + 5;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 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 行未改动29 行未改动303132333435363738394041424344454647484950515253545574 行未改动29 行未改动### 代码这里的代码添加了所有优化#### 普通代码(代码简短好写):::success[DSU - common]{open}```cppconst int N = 1e3 + 5;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 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 行未改动