Dijkstra for longest path in a DAG

后端 未结 6 2000
面向向阳花
面向向阳花 2020-12-01 14:55

I am trying to find out if it is possible to use Dijkstra\'s algorithm to find the longest path in a directed acyclic path. I know that it is not possible to find the longes

6条回答
  •  失恋的感觉
    2020-12-01 15:39

    I suggest you modify the Dijkstra's algorithm to take the inverted value of the edge weight. Because the graph is acyclic, the algorithm will not enter an endless loop, using the negative weights to keep optimising. What is more, now positive weights become negative, but, again, there are no cycles. This will work even if the graph is undirected, provided that you disallow reinsertion of visited nodes (i.e., stop the endless jumping between two nodes, because adding negative value will always be better).

提交回复
热议问题