classic kruskal algorithm, easy, good