当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5861:Road

题目描述
There are n villages along a high way, and divided the high way into n-1 segments. Each segment would charge a certain amount of money for being open for one day, and you can open or close an arbitrary segment in an arbitrary day, but you can open or close the segment for just one time, because the workers would be angry if you told them to work multiple period.

We know the transport plan in the next m days, each day there is one cargo need to transport from village $a_i$ to village $b_i$, and you need to guarantee that the segments between $a_i$ and $b_i$ are open in the i-th day. Your boss wants to minimize the total cost of the next m days, and you need to tell him the charge for each day.

(At the beginning, all the segments are closed.)
输入解释
Multiple test case. For each test case, begins with two integers n, m(1<=n,m<=200000), next line contains n-1 integers. The i-th integer $w_i$(1<=$w_i$<=1000) indicates the charge for the segment between village i and village i+1 being open for one day. Next m lines, each line contains two integers $a_i, b_i(1\leq a_i,b_i<=n, a_i!=b_i)$.
输出解释
For each test case, output m lines, each line contains the charge for the i-th day.
输入样例
4 3
1 2 3
1 3
3 4
2 4
输出样例
3
5
5
来自杭电HDUOJ的附加信息
Author BUPT
Recommend wange2014

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-5861

最后修改于 2020-10-25T23:26:15+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
12000/6000MS(Java/Others) 65536/65536K(Java/Others)