ALGORITHM 1.5 (continued) Union-find implementation (weighted quick-union)