simple union find algorithm