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 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
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?
Название |
---|
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.
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 :)
Isn't it costly in the respect of time?
It depend on the graph and the length of the initial Shortest Path
jisan047 You can find kth shortest path between two node s and t. https://en.wikipedia.org/wiki/K_shortest_path_routing