implement kruskal's algorithm