| 26 | |
| 27 | |
| 28 | class _UF: |
| 29 | def __init__(self): |
| 30 | self._p: dict[tuple, tuple] = {} |
| 31 | |
| 32 | def _ensure(self, x): |
| 33 | if x not in self._p: |
| 34 | self._p[x] = x |
| 35 | |
| 36 | def find(self, x) -> tuple: |
| 37 | self._ensure(x) |
| 38 | if self._p[x] != x: |
| 39 | self._p[x] = self.find(self._p[x]) |
| 40 | return self._p[x] |
| 41 | |
| 42 | def union(self, a, b): |
| 43 | ra, rb = self.find(a), self.find(b) |
| 44 | if ra != rb: |
| 45 | self._p[rb] = ra |
| 46 | |
| 47 | |
| 48 | def resolve_nets( |
no outgoing calls
no test coverage detected