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 ] ) swap ( p , q ) ; par [ p ] = q ; sizeContainer [ q ] += sizeContainer [ p ] ; }