Kruskal's algorithm for computing mst, implemented with union-find