luogu#P2966. [USACO09DEC] Cow Toll Paths G
[USACO09DEC] Cow Toll Paths G
题目描述
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 cows move from any of the pastures conveniently numbered to any other pasture over a set of bidirectional cowpaths that connect pairs of different pastures and . FJ has assigned a toll to the path connecting pastures and .
While there may be multiple cowpaths connecting the same pair of pastures, a cowpath will never connect a pasture to itself. Best of all, a cow can always move from any one pasture to any other pasture by following some sequence of cowpaths.
In an act that can only be described as greedy, FJ has also assigned a toll to every pasture. The cost of moving from one pasture to some different pasture is the sum of the tolls for each of the cowpaths that were traversed plus a single additional toll that is the maximum of all the pasture tolls encountered along the way, including the initial and destination pastures.
The patient cows wish to investigate their options. They want you to write a program that accepts queries and outputs the minimum cost of trip specified by each query. Query is a pair of numbers and $t_i (1 \leq s_i \leq N; 1 \leq t_i \leq N; s_i \neq t_i)$ specifying a starting and ending pasture.
Consider this example diagram with five pastures:
The 'edge toll' for the path from pasture to pasture is . Pasture 's 'node toll' is .
To travel from pasture to pasture , traverse pastures to to to . This incurs an edge toll of and a node toll of (since pasture 's toll is greatest), for a total cost of .
The best way to travel from pasture to pasture is to traverse pastures to to . This incurs an edge toll of and a node toll of , for a total cost of .
给定一个 点 边的双向图,第 条道路连接了 与 ,边权为 ,第 个点的点权为 。
给定 组询问,第 组询问求从 到 的路径的边权之和与点权的最大值的和的最小值。
可能有重边,但保证无自环。
输入格式
-
Line : Three space separated integers: , , and
-
Lines : Line contains a single integer:
-
Lines : Line contains three space separated integers: , , and
-
Lines : Line specifies query using two space-separated integers: and
第一行三个整数 代表点数,边数与询问数。
接下来 行每行一个整数 代表第 个点的点权。
接下来 行每行三个整数 代表第 条边从 连到 边权为 。
接下来 行每行两个整数 代表第 组询问求从 到 的边权之和与点权的最大值的和的最小值。
输出格式
- Lines : Line contains a single integer which is the lowest 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
提示
对于 的数据,,,。