Implementation of quickunion algorithm from sedgewick algorithms 4th edition notes.