Add union find algorithm.(partly done)