Implementation Kruskal's algorithm