#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 NN pastures, conveniently numbered 1..N1..N, connected by MM bidirectional cowpaths. Path jj connects two different pastures AjA_j and BjB_j and has an edge toll LjL_j. 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 CiC_i to every pasture ii. The cost of traveling from pasture ss to a different pasture tt 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 ss and tt.

You are given KK queries. Query ii specifies (si,ti)(s_i, t_i) and asks for the minimum possible cost of a trip from sis_i to tit_i under the rule above.

Input Format

  • Line 11: Three space-separated integers NN, MM, and KK.
  • Lines 2..N+12..N+1: Line i+1i+1 contains a single integer CiC_i.
  • Lines N+2..N+M+1N+2..N+M+1: Line j+N+1j+N+1 contains three space-separated integers AjA_j, BjB_j, and LjL_j.
  • Lines N+M+2..N+M+K+1N+M+2..N+M+K+1: Line i+N+M+1i+N+M+1 contains two space-separated integers sis_i and tit_i.

Output Format

  • Lines 1..K1..K: Line ii contains a single integer, the minimum cost of any route from sis_i to tit_i.
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: 1N2501 \leq N \leq 250, 1M1041 \leq M \leq 10^4, 1K1041 \leq K \leq 10^4, 1Ci100,0001 \leq C_i \leq 100{,}000, 1Lj100,0001 \leq L_j \leq 100{,}000.

Notes: Multiple edges between a pair of pastures are allowed, but self-loops are not. The graph is connected.

Translated by ChatGPT 5