implement UPGMA