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

建议使用的浏览器:

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

5815:Golden Week

Special Judge 特殊评判
题目描述
The ACM kingdom has N cities, numbered from 1 to N. The capital is numbered 1. There are N – 1 roads each connecting two cities in the kingdom such that there exactly one path between any pair of cities.

Now the Golden Week Vocation is coming. M travelers living in the capital are going to travel to other cities. Every traveler will start from the capital, and the ith traveler has chosen city Ci as his destination. As a manager of the travel agencies, Mr. Chopsticks decides to assign prices to the roads in the kingdom during the vocation. After some investigation, Mr. Chopsticks has found that every traveler has a budget for his trip, and if the total price of the roads in the path from the capital to his destination city is larger than his budget, he will give up his trip; otherwise he will pay for it to the travel agencies. Mr. Chopsticks wants to assign prices to roads so as to maximize the agencies’ revenue. Could you help him? Each road should be assigned a price between 0 and 1000,000,000 inclusive.
输入解释
The input begins with an integer T (T<=50), indicating the number of test cases. Each case begins with two integers N and M (2 <= N <= 1000, 1 <= M <= 1000), indicating the number of cities and the number of travelers respectively. Then N – 1 lines follow, where the ith line contains two integers $u_i$ and $v_i$ $(1 \leq u_i, v_i \leq N)$ indicating that the ith road connects the cities $u_i$ and $v_i$. The next M lines each contain two integers $C_i$ and $B_i$ $(1 \leq C_i \leq N, 1 \leq B_i \leq 1000 000 000)$, indicating the ith traveler’s destination and budget respectively.
输出解释
For each case, output a line containing the maximum revenue, followed by a line containing N – 1 nonnegative integers, separated by one space, in which the ith integer denotes the price of the ith road. If there are multiple optimum solutions, output any of them.
输入样例
2
2 3
1 2
2 3
2 5
2 9
4 4
1 2
1 3
2 4
2 4
2 7
4 5
3 6
输出样例
10
5
19
4 6 1
来自杭电HDUOJ的附加信息
Author SYSU
Recommend wange2014

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

源链接: HDU-5815

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

共提交 0

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