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