Dijkstra shortest path algorithm with edge cost

血红的双手。 提交于 2019-12-03 06:28:17
IVlad

https://www.spoj.pl/problems/ROADS/

The problem was given at CEOI '98 and its official solution can be found here.

You don't really need to modify Dijkstra's algorithm to do this as the answer is equivalent to finding the shortest path and then accepting it if it's less than or equal to A.

Of course, you could always short circuit the inner loop if you visit a path with a cost more than A.

EDIT: With the clarification that you want to minimize cost AND distance, you can't do that without clarifying the solution you want. Do you want the cheapest path? Do you want the shortest path? Do you want some function of cost and distance? All of these determine what weighting function you should use for a particular edge.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!