[go: nahoru, domu]

Skip to content

Commit

Permalink
更新 并查集 相关内容
Browse files Browse the repository at this point in the history
  • Loading branch information
itcharge committed Jun 27, 2024
1 parent 00696fe commit bdf258d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Contents/07.Tree/05.Union-Find/01.Union-Find.md
Original file line number Diff line number Diff line change
Expand Up @@ -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[root_y] += 1 # 因为层数相同,被合并的树必然层数会 +1
self.rank[root_y] += 1 # 因为层数相同,被合并的树必然层数会 +1
return True

def is_connected(self, x, y): # 查询操作:判断 x 和 y 是否同属于一个集合
Expand Down Expand Up @@ -389,7 +389,7 @@ class UnionFind:
self.fa[root_y] = root_x # y 的根节点连接到 x 的根节点上,成为 x 的根节点的子节点
else: # x 的根节点对应的树的深度 等于 y 的根节点对应的树的深度
self.fa[root_x] = root_y # 向任意一方合并即可
self.rank[y] += 1 # 因为层数相同,被合并的树必然层数会 +1
self.rank[root_y] += 1 # 因为层数相同,被合并的树必然层数会 +1
return True

def is_connected(self, x, y): # 查询操作:判断 x 和 y 是否同属于一个集合
Expand Down
2 changes: 1 addition & 1 deletion Templates/07.Tree/Tree-UnionFind-UnoinByRank.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def union(self, x, y): # 合并操作:令其中一个
self.fa[root_y] = root_x # y 的根节点连接到 x 的根节点上,成为 x 的根节点的子节点
else: # x 的根节点对应的树的深度 等于 y 的根节点对应的树的深度
self.fa[root_x] = root_y # 向任意一方合并即可
rank[y] += 1 # 因为层数相同,被合并的树必然层数会 +1
self.rank[root_y] += 1 # 因为层数相同,被合并的树必然层数会 +1
return True

def is_connected(self, x, y): # 查询操作:判断 x 和 y 是否同属于一个集合
Expand Down

0 comments on commit bdf258d

Please sign in to comment.