(self, x, y)
| 25 | return self.parent[x] |
| 26 | |
| 27 | def union(self, x, y): |
| 28 | root_x, root_y = self.find(x), self.find(y) |
| 29 | if root_x == root_y: |
| 30 | return |
| 31 | |
| 32 | if self.rank[root_x] > self.rank[root_y]: |
| 33 | self.parent[root_y] = root_x |
| 34 | elif self.rank[root_x] < self.rank[root_y]: |
| 35 | self.parent[root_x] = root_y |
| 36 | else: |
| 37 | self.parent[root_y] = root_x |
| 38 | self.rank[root_x] += 1 |
| 39 | |
| 40 | def get_groups(self) -> Dict[int, List[int]]: |
| 41 | """Returns groups as {root: [elements]}.""" |
no test coverage detected