Algorithm Kruskal: basic implementation