Implement UnionFindWithSize, a disjoint-set data structure over arbitrary integer labels that also tracks cluster sizes. A label first appears when mentioned in any operation; a brand-new label starts as a singleton cluster of size 1.
Methods
merge(x, y): merge the clusters containing x and y.
find(x): return the representative root of the cluster containing x.
count(x): return the size of the cluster containing x.
Examples
Example 1
Input["UnionFindWithSize", "merge", "find", "count"]
[[], [0, 1], [0], [0]]
Output[null, null, 1, 2]
Explanation: Merging 0 and 1 forms a cluster of size 2 rooted at 1, so find(0) is 1 and count(0) is 2.
Constraints
Labels are integers introduced lazily on first reference.
Operations should be near O(1) amortized.