graph - Dijkstra for The Single-Source Longest Path

前端 未结 3 1274
滥情空心
滥情空心 2020-12-01 21:34

Ok, I posted this question because of this exercise:

Can we modify Dijkstra’s algorithm to solve the single-source longest path problem by changing mi

3条回答
  •  离开以前
    2020-12-01 21:51

    Yes, we can. And your answer is almost correct. Except one thing.

    You assume no negative weights. In this case Dijkstra's algorithm cannot find longest path.

    But if you assume only negative weights, you can easily find the longest path. To prove correctness, just take absolute values of all weights and you get exactly the usual Dijkstra's algorithm with positive weights.

提交回复
热议问题