basic version of union-find