2436: Mart Master

内存限制:128 MB 时间限制:10.000 S
评测方式:文本比较 命题人:
提交:0 解决:0

题目描述

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