This page is still under construction.

Parts of this page are still being built. What you see may change.

Tree Advertising

Time limit1sMemory limit1024 MB

Summary
Root a tree at city 1 and choose a set of edges within budget so that the total population of cities whose path to the root contains a chosen edge is maximized.
Level

Medium7 of 10

Topics
Tree, Dynamic programming, DFS
Solved
No attempts yet

Problem

Azerbaijan has NN cities, numbered 11 through NN, connected by N−1N-1 roads so that every city can be reached from every other city along a sequence of roads. The IOI will soon be held in the capital Baku (city 11), and everyone in the country will drive from their home city to the capital to watch the competition.

You want to use this occasion to advertise your new, very clever competitive programming judge by putting up posters on many trees along various roads. If you put up posters along a road, everyone who travels along that road at some point during their trip from their home city to the capital will see the poster.

You have judged that it adds nothing if a person sees your posters more than once during their trip. Your judge is so impressive that everyone wants to use it after seeing the poster a single time! Each road has a cost for putting up posters on all trees along it, each city has a population, and you have a limited budget. If you put up posters optimally, what is the largest number of people who will see at least one poster during their trip to the capital?

Input

The first line contains two integers: the number of cities NN (1≤N≤2 0001 \le N \le 2\,000) and your budget in kronor BB (1≤B≤30 0001 \le B \le 30\,000).

The second line contains the N−1N-1 numbers p2,p3,…,pNp_2, p_3, \dots, p_N (0≤pi≤30 0000 \le p_i \le 30\,000). pip_i is the number of people who live in city ii.

The following N−1N-1 lines describe all the roads in Azerbaijan. The ii-th of these lines contains the integers ai,bia_i, b_i (1≤ai,bi≤N1 \le a_i, b_i \le N) and cic_i (1≤ci≤B+11 \le c_i \le B+1), meaning that the ii-th road runs between cities aia_i and bib_i and costs cic_i kronor to put up posters along.

It is guaranteed that all cities can be reached from each other using these roads.

Output

Print a single number: the largest number of people who can see your posters, if you place them optimally.

Hint

In the first example, it is optimal to put up one poster on the road between city 11 and city 66, and one between city 22 and city 33. This costs 350+100350 + 100 (which fits within the budget of 500500), and makes the people in cities 33, 44, 55, and 66 see the advertisement, for a total of 1000+100+300+300=17001000 + 100 + 300 + 300 = 1700 people.

Examples2

  1. Example 1

    Input
    6 500
    500 1000 100 300 300
    1 2 200
    3 2 100
    1 6 350
    5 6 501
    6 4 250
    
    Expected output
    1700
    
  2. Example 2

    Input
    6 4
    10 20 30 40 50
    1 2 1
    1 3 1
    1 4 1
    2 5 1
    3 6 1
    
    Expected output
    150