Dijkstra algo giving wrong ans

why my code is giving wrong ans:

You are assigning distance as 1e18 but when you are checking whether the distance from source to destination has changed or not, at that time you are using INT_MAX , INT_MAX is not equal to 1e18 , that’s why your code does not work.
And also no need to insert every element in set , and if you are using set you also don’t require visited array as the distance has been already updated.

Your working code

thanks for ans , got the ans. and i have one more doubt , i the implementation of this algorithm using priority queue , when we are updataing priority queue why we are only inserting elemnts not removing the previous , like we did using set implementation link:-https://www.geeksforgeeks.org/dijkstras-shortest-path-algorithm-using-priority_queue-stl/

because we take visited array while implementing dijkstra using priority_queue . Removing element will cost complexity that’s why for sake we use visited.

@apaarkamal your code is not working

because you havent understood the code , you have just copy pasted

see what the question demands, print only that

@apaarkamal how can u accuse me of copying. Just to hide your incompetence. Good then. And if it is so dont take doubts, just sit and relax

incompetence of what?
this code works fine whenever and wherever i used it.

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.