Dijkstra's Algorithm


Is there any mistake? I can’t find it.

hello @mohitsethia
add this extra condition in ur code


this is because it can happen that the key d is not present in map (dist)
which indicates that d is not reachable so we need to print -1 for them as well

@aman212yadav
Does that matter? Because the distance of that node is already Infinity.

https://ide.codingblocks.com/s/233088
Can you find any difference in this code and the above code? This was the solution that I submitted few days back and it was accepted.

ok it missed to see that part of ur code.
actually u are intialising every node(doesnt matter whether connected or not) with INT_MAX
so in ur case i dont thing the above change(i suggested is necesary).

your code should work fine , so try to submit again

Okay I guess problem was with the compiler :frowning: Wasted a lot of time during exam time

online exam ke liye kaun padta hai bhai :stuck_out_tongue_winking_eye::stuck_out_tongue_winking_eye::stuck_out_tongue_winking_eye:

It’s LEEE, I have to study to take admission in a better college :expressionless:

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.