F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Mart Master II

Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1335    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
5 1 2 1 2 3 1 3 4 1 4 5 1 1 0 0 0 1 5 1 2 1 2 3 1 3 4 1 4 5 1 1 0 0 0 0 1 1 1 0
 

Sample Output
2 4 0 1
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-06-22 04:26:44, Gzip enabled