We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 66a528b commit 5d02103Copy full SHA for 5d02103
1 file changed
data_structures/disjoint_set/disjoint_set.py
@@ -26,7 +26,10 @@ def union_set(x, y):
26
disjoint set tree will be more flat.
27
"""
28
x, y = find_set(x), find_set(y)
29
- if x.rank > y.rank:
+ if x == y:
30
+ return
31
+
32
+ elif x.rank > y.rank:
33
y.parent = x
34
else:
35
x.parent = y
0 commit comments