Apply Kruskal's algorithm (#710)