#P3451. [POI 2007] ATR-Tourist Attractions
[POI 2007] ATR-Tourist Attractions
Description
You are given an undirected graph with vertices and edges, where each edge has a weight.
You need to find a shortest path from to that, while satisfying the given constraints, can stop at every vertex numbered from to .
Each constraint is of the form , meaning that you must have stopped at before stopping at .
Note that “stop” here does not mean merely passing through.
Input Format
The first line contains three integers .
Each of the next lines contains three integers , meaning there is an edge of weight between and .
The next line contains an integer .
Each of the next lines contains two integers , representing one constraint.
Output Format
Output a single integer on one line — the length of the shortest path.
8 15 4
1 2 3
1 3 4
1 4 4
1 6 2
1 7 3
2 3 6
2 4 2
2 5 2
3 4 3
3 6 3
3 8 6
4 5 2
4 8 6
5 7 4
5 8 6
3
2 3
3 4
3 5
19
Hint
Constraints:
- For of the testdata, the following hold:
- .
- .
- .
- .
- .
- .
- There are no multiple edges, and a solution always exists.
Translated by ChatGPT 5
京公网安备 11011102002149号