This commit is contained in:
programmercarl
2023-06-10 16:54:54 +08:00
parent 5e1c10bfcc
commit cef6de49f4

View File

@ -131,7 +131,9 @@ private:
} }
// 将v->u 这条边加入并查集 // 将v->u 这条边加入并查集
void join(int u, int v) { void join(int u, int v) {
if (isSame(u, v)) return ; u = find(u); // 寻找u的根
v = find(v); // 寻找v的根
if (u == v) return ; // 如果发现根相同,则说明在一个集合,不用两个节点相连直接返回
father[v] = u; father[v] = u;
} }
public: public: