WeightedQuickUnion Algorithm with Path compression