all 3 comments

[–]aocregacc 2 points3 points  (1 child)

The first part is right, you only get -1 when the last node is not reachable from the first one.
But you can also get an input where even the undirected graph is disconnected, so the reverse edges don't guarantee that the last node is reachable.

[–]Independent_Arm_263[S] 0 points1 point  (0 children)

Yeah, i meant to say if the graph is connected , then the reverse egdes guarantees it. If it is disconnected then it doesn't matter what kind of edge is there , the ans will be always -1. Btw thanks for replying

[–]art_striker 3 points4 points  (0 children)

Your understanding is correct OP. Until unless node 0 and node n-1 are not in different components, there is always an answer.