Implementing weighted undirected graphs and Kruskal's algorithm