Union - Find algorithms implementation