simple implementation  of Kruskal's algorithm