Getting incorrect output
@Ishitagambhir
Some modifications you need to do here are:-
- Since there are possibility that dist[dest] = INT_MAX if it was not visited by dfs then print -1.
- Since there is no edge from 100 but in BFS function you are initializing the dist[] with the help of adjacency list then there will not be an index for 100 and hence it will give wrong answer.
So either addedge from 100 to 100 or you can initialize the dist array using a loop from i=1 to i=100 - while creating the adjacency list you are checking for val>0 and val<100 but second one should be val<=100 because it is allowed and required to go there.
I hope you have understood all the above things, feel free to ask if you face any other difficulty.
If you are able to solve it now then please mark this doubt as resolved.
1 Like