Implement a Disjoint Set Union (Union-Find) with path compression and union by size.
Constraints
Example
>>> uf = UnionFind(5) >>> uf.union(0, 1) >>> uf.connected(0, 1) True >>> uf.connected(0, 2) False >>> uf.find(1) 0 >>> uf.union(2, 3) >>> uf.union(1, 2) >>> uf.find(3) 0
Recent Submissions
No submissions yet — hit Run Tests to try!
Hints