Implementation of weighed quick-union (with path compression) algorithm for Union-Find problem.