Added union find algorithm implementation