×_7_12_2013 C: More happiness

Problem C: More happiness

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 1   Solved: 0
[ Submit][ Status][ Web Board]

Description

As you know, poor Xiaoming has been dreaming to go to Happyvalley for a long time. The good news is 
that today his mom finally agrees to take him there this weekend! 
In order to make his journey in Happyvalley happier, Xiaoming found a map of Happyvalley to design a 
good path. Happyvalley has N scenic spots and there are roads between them. Xiaoming found that there is 
only one way between each two spots. In other words, the N spots and roads between them form a “tree”.  
Xiaoming can start his journey from arbitrary scenic spot. It takes Ci minutes to walk from one end to the 
other end on the ith road. Xiaoming knows that he can only stay in Happyvalley for only P minutes. 
However, he is uncertain of the time he may spend in each scenic spot. So he can only guess it.  
Given the information of Happyvalley and the total time P minutes, also, with the time X Xiaoming guess he 
would spend in each spot, can you tell Xiaoming the maximum number of spots he can stay for X minutes? 
Note that each spot should be count only once. 

Input

The first line of the input is T (no more than 10), which stands for the number of test cases you need to 
solve.  
On the first line of each test case, there are two integers giving the number N (no more than 200) of scenic 
spots in Happyvalley and the total time P (no more than 2000000) Xiaoming can stay. The following N-1 
lines state the roads in the form of “a b c” which means it takes c minutes to walk from spot a to spot b or 
from b to a (1 <= a, b <= N, 1 <= c <= 10000). 
Then an integer Q (no more than 10000) in a single line is the number of queries Xiaoming asks you. Each 
of the next N lines gives a number X (no more than 10000) representing the time Xiaoming guess.

Output

Output the maximum number of spots he can get based on each guess of Xiaoming. Separate each test case 
with a blank line. 

Sample Input

2 3 10 1 2 2 2 3 1 3 10 2 4 6 15 1 2 2 1 3 1 2 6 3 5 3 5 3 4 3 4 1 2 3 100

Sample Output

1 3 2 5 4 3 0



你可能感兴趣的:(×_7_12_2013 C: More happiness)