works for Kruskal's Algorithm