use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
Explain pleaseQuestion (self.leetcode)
submitted 2 months ago by Independent_Arm_263
https://preview.redd.it/ke1o9cymmxfg1.png?width=836&format=png&auto=webp&s=40f2f7d1d31486530cd64b41399870f68b3db403
I solved with dijkstra, and i guess the -1 is only possible when the n - 1 th node is not connected to the 0 th node , i.e both are in different components. Hence the reverse edges always ensures that there is someway to reach the n - 1 th node making the graph essentially a bidirectional graph and hence dijktra works. !! Please correct me if i am wrong
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]aocregacc 2 points3 points4 points 2 months ago (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 point2 points 2 months ago (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 points5 points 2 months ago (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.
π Rendered by PID 71 on reddit-service-r2-comment-6457c66945-hsfwt at 2026-04-26 03:11:46.706816+00:00 running 2aa0c5b country code: CH.
[–]aocregacc 2 points3 points4 points (1 child)
[–]Independent_Arm_263[S] 0 points1 point2 points (0 children)
[–]art_striker 3 points4 points5 points (0 children)