accomplish Kruskal's algorithm