kruskal's algorithm for extremal spanning trees