you have used a max heap in your c++ code which is wrong. python on the other hand has a minheap by default.
1 Like
thanks totally forgot
Exactly! Nice catch.
@kshitij_789 You confused yourself with Dijkstra and DFS. You used a visited bool array like in DFS and used a heap (max heap) like in Dijkstra. This caused the problem, as once a vertex was relaxed, it wasnât being relaxed again (even when a shorter path existed), leading to incorrect answers.
I remove that in contest see I had around 10 submissions.maybe you didnât check the other ones.
problem was I used max_heap and used it like a min heapâŚ
lesson learnt-do not overcomplicate bfs to djikstra
1 Like