简体   繁体   中英

Why can't Bellman-Ford be used for Single Source Longest Path?

Dijkstra's cannot be used for longest path because it uses the property that the current shortest path will be for sure shorter than one of the other paths. This is correct, of course, assuming there are no negative edge weights. This concept is also why longest path doesn't work on Dijkstra, because the current longest path doesn't guarantee that there won't be another longer path that takes a larger value later on.

On the other hand, Bellman Ford offers the the flexibility of negative weights at a worse performance. This means that for Bellman Ford, so it doesn't work on the same greedy property as Dijkstra. So that's why I'm confused - why can't Bellman Ford be used on the Single Source Longest Path problem(NP hard)? For example, we can simply multiply all the weights of a graph by -1 and find the shortest path, which would be the longest path of the original graph.

Bellman-Ford 允许重复使用弧(否则即使存在负循环也会有明确定义的最短路径),而单源最长路径问题从它不这样做的事实中推导出其 NP 难度(否则你可以只需在将所有权重乘以 -1 后使用 Bellman-Ford)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM