mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 09:21:13 +08:00
@ -26,7 +26,10 @@ def union_set(x, y):
|
|||||||
disjoint set tree will be more flat.
|
disjoint set tree will be more flat.
|
||||||
"""
|
"""
|
||||||
x, y = find_set(x), find_set(y)
|
x, y = find_set(x), find_set(y)
|
||||||
if x.rank > y.rank:
|
if x == y:
|
||||||
|
return
|
||||||
|
|
||||||
|
elif x.rank > y.rank:
|
||||||
y.parent = x
|
y.parent = x
|
||||||
else:
|
else:
|
||||||
x.parent = y
|
x.parent = y
|
||||||
|
Reference in New Issue
Block a user