There is the following task: to find the minimum path and find the second minimal path, while the second minimal path should not completely contain the first minimal path.
Examples ("1)" - the minimum path, "2)" - the second minimum path, the node numbers are indicated): 1.1) 1-3-5 2) 1-2-3-4-5 2 way completely contains the first.
2.1) 1-3-5 2) 1-2-5 2 path does not contain 3 node with 1 path.
3.1) 1-3-5 2) 2-4-5 It can also be correctly correct.
The implementation of the algorithm is as follows:
- Using Dijkstra's algorithm to find the first minimum path.
- Write the resulting minimum path (i.e. node numbers) to the array.
- ?????? And actually there is a problem - how to start finding the next minimal paths. The assumption that the second minimum value is the second minimum distance of the neighbors of the target node (Example: there is a target node N with neighbors N-1 (distance - 6) N-2 (8) N-3 (11), that is, theoretically the second minimum is the path through N-2) is not always true. you may need to change the node in the first way in the middle and get a smaller value (in the example you will need to change the used N-8-> N-5 edge with a weight of 1 to the edge of N-9-> N-5 with a weight on the way to N-1 2, the distances to N-8 and N-9 are identical, and then we get the minimum way with a weight of 7).
The question is how to find this second way?