问题
I was wondering if I can modify Dijkstra’a Alghorithm in this way: Let’s say there are 2 paths between two vertices with following lengths:
5, 8, 6, 9 // sum=28
2, 4, 8, 25 //sum=39
First path is shorter but after ignoring the longest edge in both I get the following sums: 19 and 14, so I choose the second path.
Maybe there is different way to solve it, without using Dijkstra?
回答1:
I'm not sure is this idea working, but on first it seems to me like it can.
For each visited node, beside distance D(n)
, store length of longest edge on the path to it, say L(v)
. Distance of unvisited neighbouring node is min D(n) + L(n) - max(L(n), weight(v,n))
, for all neighbours n
that are visited. L(v)
of next visited node is max(L(n), weight(v,n))
, if n
is last node on a path to the v
. If there are more paths to v
(more n's
) with same length, than choose one with largest L(v)
.
来源:https://stackoverflow.com/questions/14159787/finding-the-shortest-path-with-possibility-of-ignoring-1the-longest-edge