Help Needed In CSES Graph Problem Longest Routes

Revision en2, by Gagandeep98, 2020-06-05 17:13:27

My logic is giving WA on 50% of the test cases. I am not able to figure out what is wrong with my logic. Any help would be great.

Logic: I apply a regular dfs, and return true or false. True indicates, that it is indeed the shortest the path, while false indicates, that it is not. If we get a true, then we update the parent node, else we don't.

Code: Code

UPDATE: Solved using DP but would be curious to know, if anyone can do it without DP.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English Gagandeep98 2020-06-05 17:13:27 89
en1 English Gagandeep98 2020-06-05 16:33:21 440 Initial revision (published)