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

建议使用的浏览器:

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

4894:Mart Master

题目描述
Trader Dogy lives in city S, which consists of n districts. There are n - 1 bidirectional roads in city S, each connects a pair of districts. Indeed, city S is connected, i.e. people can travel between every pair of districts by roads.

In some districts there are marts founded by Dogy's competitors. When people go to marts, they'll choose the nearest one. In case there are more than one nearest marts, they'll choose the one with minimal district number.

Dogy's money could support him to build at most m new marts, but he can't build new marts in the district which already had his competitors's marts. he wants to attract as many people as possible, that is, to build his marts in some way that maximize the number of people who will choose his marts as favorite. Could you help him?
输入解释
There are several test cases, please process till EOF.

In each testcase:
First line contains two numbers n and m(1 ≤ m ≤ n ≤ 200).
Next n - 1 lines, each contains three numbers bi, ei and wi, (1 ≤ bi, ei ≤ n, 1 ≤ wi ≤ 10000), indicates that there's one road connecting city bi and ei, and its length is wi.

Last line contanins n numbers, each number is either 0 or 1, ith number is 1 indicates that the ith district has mart in the beginning and vice versa.
输出解释
For each testcase, output one number, denoting the maximum number of districts of people you can attract.
输入样例
5 1
1 2 1
2 3 1
3 4 1
4 5 1
1 0 0 0 1
5 2
1 2 1
2 3 1
3 4 1
4 5 1
1 0 0 0 1
输出样例
2
3
来自杭电HDUOJ的附加信息
Author Fudan University
Recommend

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

源链接: HDU-4894

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

共提交 0

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