why is this code not getting submitted it shows wrong answer plz tell the reason and correct the code.
Dijkstra algorithm problem c++
@S19LPPP0202
You need to update the distance array for neighbours only when the distance using current node is less than the distance previously stored.
Also incase dist is INT_MAX print -1, not INT_MAX, as given in problem.
here is the code you asked for https://ide.codingblocks.com/s/235232
Also please mark this doubt as resolved if you are able to understand it now.
i think that i didnt handle this case:
incase dist is INT_MAX print -1, not INT_MAX, as given in problem.
rest of my code is fine …right??
You need to update the distance array for neighbours only when the distance using current node is less than the distance previously stored.
does my code have any error as far as this case is concerned??
i have asked one more doubt regarding dijkstra algo in a seperate doubt plz solve that as well…
@S19LPPP0202 ya your code is fine.
If you have opened separate doubt then it will be answered soon by a TA.
For now please mark this doubt as resolved .
how to print the path in dijkstra algo code…plz add that part in my code…
For that just made a parent array which will store the parent of node.
According to your code, see whenever it updates the distance for any node, then at that time also update the value in parent[] array for that node.
At last just start from destination, and keep moving in reverse order till the source is not found.
sample code for this step will be like:-
int node = destination;
while(parent[node]!=source){
cout<<parent[node];
node = parent[node];
}
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.