Https://ide.codingblocks.com/s/207191 BFS-Shortest path

sir i have tried dijktras approach but 1 answer is showing wrong upon submission

@Adarshrajpandey You don’t need to use dijkstra for this question. This can be solved using bfs traversal. And the time for dijkstra will be nlogn whereas for bfs it will be 0(n)

https://ide.codingblocks.com/s/207493 sir

i have done this using bfs but it is not passing showing tle in one and wrong ans in the other

please check this code

@Adarshrajpandey This is not a proper way to check visited array. unordered_map<int,bool>visited;
Initially it is empty so none of the nodes are assigned any value. Use an array for visited check.

https://ide.codingblocks.com/s/207751 sir tried this many times but not running

please check sir,sorry for the inconvenience caused sir

but please tell the mistake as i m not able to find out

@Adarshrajpandey initialise the distance of each node as infinity

I have tired the as u hae told but one answer is ginving wrong!

https://ide.codingblocks.com/s/207751 is the link

@Adarshrajpandeysince you are very close to the answer I would leave it as a homework for you to learn and understand how the BFS works and get your code accepted yourself.

thanks sir for working so hard on me!!

@Adarshrajpandey No problem dude.