Quick union algorithm implementation.