You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

disjoint.py 390B

5 months ago
123456789101112131415161718
  1. class DisjointValue():
  2. def __init__(self, value):
  3. self.value = value
  4. self.parent = None
  5. def canonical(self):
  6. if self.parent:
  7. return self.parent.canonical()
  8. return self
  9. def same_set(self, other):
  10. return self.canonical() == other.canonical()
  11. def union(self, other):
  12. self.canonical().parent = other.canonical()