Question: #include #include #include / / for pair using namespace std; struct Edge { int dest; int weight; } ; class Graph { private: int V;
#include
#include
#include for pair
using namespace std;
struct Edge
int dest;
int weight;
;
class Graph
private:
int V;
vector adjList;
public:
Graphint vertices : Vvertices
adjList.resizeV;
Function to add an edge between two vertices with a weight.
void addEdgeint src int dest, int weight
Edge edge;
edge.dest dest;
edge.weight weight;
adjListsrcpushbackedge;
edge.dest src;
adjListdestpushbackedge;
void display
for int v ; v V; v
cout "Vertex v connects to:
;
for const Edge& edge : adjListv
cout Vertex edge.dest with weight edge.weight
;
cout
;
;
int main
Create a graph with vertices
Graph cityNetwork;
cityNetwork.addEdge;
cityNetwork.addEdge;
cityNetwork.addEdge;
cityNetwork.addEdge;
cityNetwork.display;
return ;
How could you implement Prims algorith to find the minimum spanning tree to this?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
