optimize performance of quick union by maintaining balance.