a little bit faster Kruskal's algo