Блог пользователя jisan047

Автор jisan047, история, 7 лет назад, По-английски

How to find second shortest path? I can find shortest path between 2 nodes. But i need to find second shortest path between 2 nodes. How to do this?

  • Проголосовать: нравится
  • +1
  • Проголосовать: не нравится

»
7 лет назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

Consider there isn't edge with negative cost.

The second path differs from first one in at least one edge, it has at least one edge that doesn't appear in first one. For each vertex find it's distance from Source (dsv) and Destination (ddv).

Find some shortest path, for each edge that doesn't appears in this shortest path, consider this edge connects v and u and it's cost is w, the shortest path from Source to Destination that passes from this edge is min {dsv + w + ddu, dsu + w + ddv}.

Finally find minimum of these values, it's the answer.

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

My Idea is that you can save the Edges used in the shortest path in a vector, disable an Edge every time and try to find the shortest path , the shortest path found while ignoring one of the Edges used in the shortest path is the Second shortest path :)

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

jisan047 You can find kth shortest path between two node s and t. https://en.wikipedia.org/wiki/K_shortest_path_routing