From 95740e9661e94c1e49669c3895b0d77e3bd2d92a Mon Sep 17 00:00:00 2001 From: Xin Wang Date: Tue, 25 Jun 2024 19:46:06 +0800 Subject: [PATCH] Update 01.Union-Find.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 按秩合并的时候,应该是y对应的根节点`root_y`的秩加一 --- Contents/07.Tree/05.Union-Find/01.Union-Find.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Contents/07.Tree/05.Union-Find/01.Union-Find.md b/Contents/07.Tree/05.Union-Find/01.Union-Find.md index df417128..7c9dd636 100644 --- a/Contents/07.Tree/05.Union-Find/01.Union-Find.md +++ b/Contents/07.Tree/05.Union-Find/01.Union-Find.md @@ -251,7 +251,7 @@ class UnionFind: self.fa[root_y] = root_x # y 的根节点连接到 x 的根节点上,成为 x 的根节点的子节点 else: # x 的根节点对应的树的深度 等于 y 的根节点对应的树的深度 self.fa[root_x] = root_y # 向任意一方合并即可 - rank[y] += 1 # 因为层数相同,被合并的树必然层数会 +1 + rank[root_y] += 1 # 因为层数相同,被合并的树必然层数会 +1 return True def is_connected(self, x, y): # 查询操作:判断 x 和 y 是否同属于一个集合