update edges and add kruskal algorithm