What does Bellman-Ford algorithm detects? Negative weight or negative cycle?

前端 未结 2 637
梦谈多话
梦谈多话 2021-02-09 06:33

If we are given a graph, Now from source we are to calculate the shortest path. Now , If an edge has a negative weight , but there is edge to back-edge to get back to that edge

2条回答
  •  梦如初夏
    2021-02-09 07:05

    You can refer this link for determining actual negative cycle. https://cp-algorithms.com/graph/finding-negative-cycle-in-graph.html In last iteration of the algo . We only get to know about the effected node . Effected because of negative cycle. The actual negative cycle forms a infinite loop of parent[parent[parent].

    Second loop of the code is like throwing a pinball from the top, after some time the ball revolves around a circular maze infinitely. We find that circular maze.

提交回复
热议问题