Prim's and Kruskal's implementation