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 cases there are more than one nearest marts, they’ll choose the one with minimal city number.
Dogy’s money could support him to build only
one new 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 mart as favorite. Could you help him?
There are multiple test cases. Please process till EOF.
In each test case:
First line: an integer n indicating the number of districts.
Next n - 1 lines: each contains three numbers b
i, e
i and w
i, (1 ≤ b
i,e
i ≤ n,1 ≤ w
i ≤ 10000), indicates that there’s one road connecting city b
i and e
i, and its length is w
i.
Last line : n(1 ≤ n ≤ 10
5) numbers, each number is either 0 or 1, i-th number is 1 indicates that the i-th district has mart in the beginning and vice versa.
For each test case, output one number, denotes the number of people you can attract, taking district as a unit.