Longest path in a DAG

前端 未结 3 960
小蘑菇
小蘑菇 2020-12-09 18:58

To find the longest path in a DAG, I\'m aware of 2 algorithms: algo 1: do a topological sort + use dynamic programming on the result of the sort ~ or ~ algo 2: enumerate all

3条回答
  •  被撕碎了的回忆
    2020-12-09 19:54

    Your second option is incorrect: DFS does not explore all possible paths, unless your graph is a tree or a forest, and you start from the roots. The second algorithm that I know is negating the weights and finding the shortest path, but it is somewhat slower than the top sort + DP algorithm that you listed as #1.

提交回复
热议问题