#P2966. [USACO09DEC] Cow Toll Paths G
[USACO09DEC] Cow Toll Paths G
Description
Like everyone else, FJ is always thinking up ways to increase his revenue. To this end, he has set up a series of tolls that the cows will pay when they traverse the cowpaths throughout the farm.
The farm is modeled as an undirected graph with pastures, conveniently numbered , connected by bidirectional cowpaths. Path connects two different pastures and and has an edge toll . There may be multiple cowpaths connecting the same pair of pastures, but no cowpath connects a pasture to itself. The graph is connected, so a cow can always move from any pasture to any other pasture by following some sequence of cowpaths.
FJ has also assigned a toll to every pasture . The cost of traveling from pasture to a different pasture along any path is the sum of the edge tolls on that path plus a single additional toll equal to the maximum of all the node tolls encountered along the way, including and .
You are given queries. Query specifies and asks for the minimum possible cost of a trip from to under the rule above.
Input Format
- Line : Three space-separated integers , , and .
- Lines : Line contains a single integer .
- Lines : Line contains three space-separated integers , , and .
- Lines : Line contains two space-separated integers and .
Output Format
- Lines : Line contains a single integer, the minimum cost of any route from to .
5 7 2
2
5
3
3
4
1 2 3
1 3 2
2 5 3
5 3 1
5 4 1
2 4 3
3 4 4
1 4
2 3
8
9
Hint
Constraints: , , , , .
Notes: Multiple edges between a pair of pastures are allowed, but self-loops are not. The graph is connected.
Translated by ChatGPT 5
京公网安备 11011102002149号