编程介的小学生 2017-08-07 02:22 采纳率: 20.5%
浏览 787
已采纳

Mart Master

Problem Description
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?

Input
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.

Output
For each testcase, output one number, denoting the maximum number of districts of people you can attract.

Sample Input
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

Sample Output
2
3

  • 写回答

1条回答

  • threenewbee 2017-08-19 14:15
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容