My code passes the sample test case! It cannot pass other cases!! Help me to find out the mistake
Dijkstra's Algorihtm
@mohammadabdullahjawwad first thing is you are taking input of n, m i opposite order, accordingly correct that.
Also initialize the dist map for all the node from i=1 to n. You are initializing the nodes which are in your graph’s adjacency list only. but there may be node which not connected to anyone(all alone).
for d.second==INT_MAX you also need to print ‘-1’ as given in question for unreachable node.
Let me know if you are not getting something i said.
I am still not getting correct answer
@mohammadabdullahjawwad its because you are not using the if else statements in correct way.
first check for int_max then for 0 or not 0.
for(int i=1; i<=n; i++){
if(dist[i] == INT_MAX){
cout<<"-1"<<" ";
}
else if(dist[i]!=0){
cout<<dist[i]<<" ";
}
}
Yes that was the problem !! Thank You