Dijkstra's algorithm with negative weights

后端 未结 7 1452
有刺的猬
有刺的猬 2020-11-30 01:06

Can we use Dijkstra\'s algorithm with negative weights?

STOP! Before you think \"lol nub you can just endlessly hop between two points and get an in

7条回答
  •  北荒
    北荒 (楼主)
    2020-11-30 01:56

    You can use Dijkstra's on a negative weighted graph but you first have to find the proper offset for each Vertex. That is essentially what Johnson's algorithm does. But that would be overkill since Johnson's uses Bellman-Ford to find the weight offset(s). Johnson's is designed to all shortest paths between pairs of Vertices.

    http://en.wikipedia.org/wiki/Johnson%27s_algorithm

提交回复
热议问题