Can you tell my mistake?

Hi Vageesha. ur code is perfectly fine. just there is one problem
image
here u should iterate over all nodes as some nodes may not bee reachable so their distance would be -1. so u should run a loop from 1 to n.

Sir, I did not understand what is wrong with this way. The ones whose distance will be INT_MAX will become -1 and all the nodes are included i the distance map

u filled the distance map by iterating over ur adjacency list.
image
say ur node is present in graph but not connected to any node then it wont be included in ur adjacency list


this is my personal code. u can refer it

1 Like

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.