Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.32 KB | None | 0 0
  1. class UF:
  2.  
  3. def __init__(self, names):
  4. self.buckets = dict((i, i) for i in names)
  5.  
  6. def union(self, a, b):
  7. self.buckets[self.find(a)] = self.find(b)
  8.  
  9. def find(self, a):
  10. if self.buckets[a] == a:
  11. return a
  12. else:
  13. return self.find(self.buckets[a])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement