Hello!
I was tasked to create a program that would output the shortest paths to all other nodes. So for example in this photo, with source A, ( https://www.includehelp.com/cpp-tutorial/Images/d0.jpg ) the output will be:

A-B
A-C
A-B-G-E-D
....

Current Output:

 `` `` ``AC ED BG E FD ``

*It shows the correct path but I just can't figure out how to somehow connect them.

So far, I have been able to compute the shortest path costs from the source to each node using Dijkstra's Algorithm. However, I can't seem to figure out how to output the "correct path directions" as seen above.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210`` ``````#include #include #include #include using namespace std; int src = 0; int vertex; struct node { string source; vector dest; vector cost; }; int minimumcost(vector cost, vector Cset, vector Node); void dijkstra(vector> graph, vector Node); vector> graph(vector Node); string delimiter(string temp); void Print(vector> listed); int main() { vector Node; vector _dest,_dest1; string root; string temp1; string temp2; int cost; int i = 0; int check = 0; for(int i=0;i>temp1; if(temp1 == "root"){ cin>>root; break; } temp1 = delimiter(temp1); for(int j=0; j>temp2; temp2 = delimiter(temp2); Node[j].dest.push_back(temp2); _dest.push_back(temp2); cin>>cost; Node[j].cost.push_back(cost); check = 1; break; } } if(check == 0){ Node.push_back(node()); Node[i].source = temp1; cin>>temp2; temp2 = delimiter(temp2); Node[i].dest.push_back(temp2); _dest.push_back(temp2); cin>>cost; Node[i].cost.push_back(cost); i++; } check = 0; } sort(_dest.begin(), _dest.end() ); _dest.erase( unique( _dest.begin(), _dest.end() ), _dest.end() ); for(int i=0; i<_dest.size(); i++){ for(int j=0; j> graph(vector Node){ int V = Node.size(); vector temp(V, 0); vector elements; vector> graph(V, temp); cout<<" "; for(int i=0; i cost, vector Cset, vector Node) { int min = INT_MAX; int index; for(int v=0;v> graph, vector Node){ vector Cost(vertex,0); vector Cset(vertex,0); vector elements; vector temp(1," "); vector> listed(vertex, temp); for(int i=0; i> listed){ vector> temp; for(int i = 0; i

Input:
 ``12345678910111213`` ``````A, B, 5 A, C, 3 D, A, 2 B, C, 2 C, D, 7 B, G, 1 B, E, 3 C, E, 7 E, D, 2 D, F, 6 G, E, 1 E, F, 1 root A``````
Last edited on