Chase

Jerry walks a simple path in a tree, dropping up to v breadcrumbs that zero out neighbor pigeon counts; maximize the pigeons Tom later meets minus the pigeons Jerry met.

Hard8TreeDynamic programmingDFSNo attempts yetTime limit4sMemory limit512 MB

Problem

Tom the cat is chasing Jerry the mouse again. Jerry wants an advantage, so he runs into crowds of pigeons where Tom has a harder time following him. He has just arrived at the central park of Ljubljana. The park has nn statues, numbered 11 to nn, and n1n-1 passages that do not cross each other and connect the statues so that every statue can be reached from every other statue. Around statue ii there are pip_i pigeons.

Jerry has vv breadcrumbs in his pocket. If he drops a breadcrumb at the statue he is standing at, the pigeons of every statue that a passage connects directly to it immediately fly to this statue to eat the crumb. As a result the number of pigeons pp around this statue and around its neighbours changes.

Everything happens in this order. First Jerry arrives at statue ii and meets the pip_i pigeons that are there. Then he drops the breadcrumb. Then he leaves the statue. The pigeons of the neighbouring statues move to statue ii before Jerry arrives at the next statue, so they do not count toward the number of pigeons he meets.

Jerry may enter the park at any statue and run along passages, but he may never use the same passage twice, and he leaves the park wherever he wants. After Jerry exits the park, Tom enters and walks exactly the same route. By dropping at most vv breadcrumbs, Jerry wants to maximise the difference between the number of pigeons Tom meets on the route and the number of pigeons he meets himself. Only the pigeons that are at a statue right before Jerry arrives there count toward his own total.

Input

The first line contains the number of statues nn and the number of breadcrumbs vv. The second line contains nn integers p1p_1 to pnp_n, separated by spaces. Each of the next n1n-1 lines contains two integers aia_i and bib_i, which mean that a passage connects statue aia_i and statue bib_i.

Output

Print one integer, the maximum difference between the number of pigeons Tom meets and the number of pigeons Jerry meets.

Constraints

  • 1n1051 \le n \le 10^5
  • 0v1000 \le v \le 100
  • 0pi1090 \le p_i \le 10^9

Note

In the first example one optimal route is the following. Jerry enters the park at statue 6 and meets 5 pigeons there. He drops a breadcrumb, so p6p_6 becomes 27 and p5=p7=p8=p9=0p_5 = p_7 = p_8 = p_9 = 0. Next he runs to statue 7 and meets 0 pigeons. He drops the second breadcrumb, so p7p_7 becomes 41 and p2=p4=p6=p10=0p_2 = p_4 = p_6 = p_{10} = 0. He exits the park. He met 5+0=55 + 0 = 5 pigeons. Tom follows the same route and meets p6+p7=0+41=41p_6 + p_7 = 0 + 41 = 41 pigeons. The difference is 415=3641 - 5 = 36.