This is called union by rank, i.e. depth in our case. If 2 roots are going to be merged, the higher ranked one will be the new root.