Union by rank , the rank in this case is sizeContainer of the component . Smaller sizeContainer will be merged into larger , so the larger 's root will be  final root
if ( sizeContainer [ p ] > sizeContainer [ q ] ) : NEW_LINE INDENT p = p + q ; NEW_LINE q = p - q ; NEW_LINE p = p - q ; NEW_LINE DEDENT par [ p ] = q ; NEW_LINE sizeContainer [ q ] += sizeContainer [ p ] ; NEW_LINE