Why I'm giving wrong answers?

I was trying to solve bfs shortest path question in graphs. I’ve made code, but it’s not clearing test cases.

I’m not able to find the reason, plz help me find that.

Here’s my code: https://ide.codingblocks.com/s/348920

hello @siddharth_1_3277

image
why r u printing -1 ?

-1 is printed as the distance to those nodes, which are not reachable from the source.

@siddharth_1_3277
that is the mistake u need to print distance in order (1st vertex then 2nd vertex then 3rd so on)

i have corrected ur code pls check it here->

1 Like

I got it… Thanks