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

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 308    Accepted Submission(s): 81


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
 

Author
Fudan University
 

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-11-22 12:39:39, Gzip enabled