Union-Find data structure with path compression.
Refactored union find data structure.