WA on Submit, cant pass unreachable case scenario

Hello TA
My sample test case is passing but I am missing some corner case for unreachable node. Please guide how to consider that case! Here is my code

@hargovind
While printing distance, you can check this condition for unreachable nodes
if(d.second==INT_MAX){ cout<<"-1 "; }
else{ cout << d.second << " "; }

Its still giving WA. This is the updated code https://ide.codingblocks.com/s/239921

@hargovind
There are few more mistakes in your code
1)use normal map not unordered map
2) you have to insert distance[i]=INT_MAX in map for 1<=i<=n, not for i<=m
I have modified your code. Check it here https://ide.codingblocks.com/s/239927

1 Like

Thanks a lot, it worked. unorderd_map was the problem. Thank you again!