|
||||||||||
Mart Master IITime Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1336 Accepted Submission(s): 492 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 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? Input 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 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 : n(1 ¡Ü n ¡Ü 105) 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. Output For each test case, output one number, denotes the number of people you can attract, taking district as a unit. Sample Input
Sample Output
Source | ||||||||||
|