Single source shortest path using bfs graphs

wrong output…please tell the mistake

@hg11110000 its giving output after removing this line
image

0 --> 0
1 --> 1
2 --> 2
3 --> 3
4 --> 4
5 --> 5

this output is wrong

that is just a setup for competitive programming

@hg11110000 this input is correct for the input you provided. How is it wrong?

@hg11110000 i know it is setup for competitive programming but you can see for yourself what the issue is.

0 --> 0
1 --> 1
2 --> 1
3 --> 1
4 --> 2
5 --> 3

this should be the output
like shortest distance from source 0 to every node ??

@hg11110000 look at the graph input you provided, draw it on pen and paper.
Your graph is like this

0 - 1 - 2 - 3 - 4 - 5

So the output is correct

oops ! gave wrong input
missed one edge

1 Like

@hg11110000 is everything clear now?

yes…thanks :)…

@hg11110000 please mark your doubt as resolved in that case :slight_smile: