Dijkstra's algorithm

I’m getting memory limit exceeded error on this implementation. Where am I going wrong?

Maybe this is a overflow problem. try to set the distance vector and queue set type to long long instead int. And adjust the INF too.

But wouldn’t that give wrong answer due to overflow of int??

Random negative distances can also put Dijkstra in an infinite (or very large) loop. Because of this, maybe his Dijkstra is inserting too many elements in the set q, causing MLE.

But in question there is no negative distance!

If there is an overflow, a negative distance can be created.

You can rule it out quite easily.