Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class UF:
- def __init__(self, names):
- self.buckets = dict((i, i) for i in names)
- def union(self, a, b):
- self.buckets[self.find(a)] = self.find(b)
- def find(self, a):
- if self.buckets[a] == a:
- return a
- else:
- return self.find(self.buckets[a])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement