Implementation of quick-union algorithm for Union-Find problem.