An alternative minimum spanning tree algorithm is due to Prim [ 121. It works by growing a single tree in successive stages. Start by picking any node as the root. At the start of a stage, some nodes are part of the tree and the rest are not. In each stage, add the minimumcost edge that connects a tree node with a nontree node. An implementation of Prim's algorithm is essentially identical to Dijkstra's shortest-path algorithm given in Section 15.3, with an update rule:

(instead of d_{w}=min(d_{w}, d_{v} + c_{v}._{w})). Also, as the graph is undirected, each edge appears in two adjacency lists. Implement Prim's algorithm and compare its performance to that of Kruskal's algorithm.