Getiing Wrong Output

hello @G_rahil
your code is correct and giving correct output.
this is ur input graph
0 - 1- 2-3-4-5

clearly
distance of node 1 from 0 is 1
distance of node 2 from 0 is 2
distance of node 3 from 0 is 3
distance of node 4 from 0 is 4
distance of node 5 from 0 is 5