接受单个负边的 Dijkstra 算法
Dijsktra's Algorithm to accept a single negative edge
所以我最近一直在使用 Dijkstra 算法和有向图。但是,我似乎无法弄清楚这一点,这真的开始困扰我了。
Show how to modify Dijkstra’s algorithm to solve the single source shortest
path problem if there is exactly one negative weight edge but no negative
weight cycles.
到目前为止,我最初的想法是以某种方式拆分图表并分别执行算法,但这就是我想到的全部内容。
我确实找到了我正在寻找的解释,但我似乎无法理解 his explanation
Well answered! I'd like to point out that if the number of negative edges is limited, there are Dijkstra-based algorithms that might do a better job. For example, if there is only one negative edge from u to v, you could run Dijkstra on s and on v, and then take the minimum for each vertex between d[s]
and d[s]+w(u, v)+d[v]
, giving a complexity of running Dijkstra twice
移除下降沿 (u, v)
, 运行 Dijkstra 两次:一次从 s
(D1
) 开始,一次从 v
(D2
)
s
和t
之间的最短路径是:min(D1[t], D1[u]+D2[t]+w(u, v))
.
所以我最近一直在使用 Dijkstra 算法和有向图。但是,我似乎无法弄清楚这一点,这真的开始困扰我了。
Show how to modify Dijkstra’s algorithm to solve the single source shortest path problem if there is exactly one negative weight edge but no negative weight cycles.
到目前为止,我最初的想法是以某种方式拆分图表并分别执行算法,但这就是我想到的全部内容。
我确实找到了我正在寻找的解释,但我似乎无法理解 his explanation
Well answered! I'd like to point out that if the number of negative edges is limited, there are Dijkstra-based algorithms that might do a better job. For example, if there is only one negative edge from u to v, you could run Dijkstra on s and on v, and then take the minimum for each vertex between
d[s]
andd[s]+w(u, v)+d[v]
, giving a complexity of running Dijkstra twice
移除下降沿 (u, v)
, 运行 Dijkstra 两次:一次从 s
(D1
) 开始,一次从 v
(D2
)
s
和t
之间的最短路径是:min(D1[t], D1[u]+D2[t]+w(u, v))
.