Please check this

if let suppose we have directed graph
and have to apply dijkastra algortihm
on it so their is one case possible ;
the case this their is atlest one node which have not any neighbour .and when i printing the distance
since it is directed graph in my adjacency list
this node is not present please checl how to handle it


check 5 have distance 0 please

since you have intialized your dist with INT_MAX so after applying dijstras if we get dist[i] =INT_MAX for ith node then that would mean that the ith node is not connected , also while printing the distance don’t iterate the adjacency list for the nodes as you mentioned some nodes won’t be present in the adjacency list instead iterate through range 1 to n so that you cover every node , refer below code for better understanding :-

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.