fix oopsie

This commit is contained in:
Pragy Agarwal 2020-03-17 19:17:10 +05:30 committed by GitHub
parent 480d4cf830
commit 328ca111a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -38,6 +38,7 @@ class DisjointSet(Generic[T]):
Amortized Time Complexity per query: ~O(1)
"""
x, y = self.find_root(x), self.find_root(y)
if x == y: return # if both x and y are already in the same component, do thing
if self.size_of(x) < self.size_of(y):
x, y = y, x # swap so that y is always the larger component
self._parents[y] = x