BFS Shortest path

plz check my code . Mycode is showing wrong answer

kindly check my code and correct it

problem : https://online.codingblocks.com/app/player/39658/content/77399/5090/code-challenge

code : https://ide.codingblocks.com/s/210940

plz reply asap

Hi @sengarankit98, by a quick glance the problem i found are

  1. you are not pushing the child nodes into the queue if they are not visited inside your while loop
  2. you have to print the distance in an ordered manner as given in question

print a single line of n-1 space-separated integers listing node s’s shortest distance to each of the n-1 other nodes (ordered sequentially by node number);

  1. there is no need for visited if you already have distance as you can use distance to know the visited nodes

here, i have corrected your code : - https://ide.codingblocks.com/s/211013

In case of any doubt feel free to ask :slight_smile:
If you got the answer then mark your doubt as resolved