Add comments to the code and display output Int main(void) //Input array containing edges of the graph //(X,Y,W)tuple represents an edge from 'x' to y' having weight w' struct Edge edges I= {0,1,4.).(1,2,4).(2,0,4),(2,1,4) int n=size of (edges)/size of (edges|0]); struct Graph *graph=createGraph(edges,n); return 0; static int minsum=100000; static void getMinPathSum(Dictionarygraph,bool[visited,ArrayLi necessary,int source,int dest,int currsum) if(src==dest) bool flag=true; for each(int i in necessary) if(!visitedi]) flag=false; break: if (flag ) minsum=Math. Min(minsum,currsum); return; elsel visited[src]=true; for(auto node:graph[src]) if (Ivisited[node.first]) visited [node.first])=true; getMinPathSum(graph, visited, necessary,node.first,dest,currsum+node.second); visited [node.first]=false;
Add comments to the code and display output
Int main(void)
//Input array containing edges of the graph
//(X,Y,W)tuple represents an edge from 'x' to y' having weight w'
struct Edge edges I=
{0,1,4.).(1,2,4).(2,0,4),(2,1,4)
int n=size of (edges)/size of (edges|0]);
struct Graph *graph=createGraph(edges,n);
return 0;
static int minsum=100000;
static void
getMinPathSum(Dictionary<int,ArrayList>graph,bool[visited,ArrayLi
necessary,int source,int dest,int currsum)
if(src==dest)
bool flag=true;
for each(int i in necessary)
if(!visitedi])
flag=false;
break:
if (flag )
minsum=Math. Min(minsum,currsum);
return;
elsel
visited[src]=true;
for(auto node:graph[src])
if (Ivisited[node.first])
visited [node.first])=true;
getMinPathSum(graph, visited,
necessary,node.first,dest,currsum+node.second);
visited [node.first]=false;
Step by step
Solved in 2 steps