Delivery Guy

On a tree of N restaurants with demand A_i, maximize total delivered peppers in M time units, where each visit costs 1 to deliver and each edge costs 1 to traverse.

Medium7TreeDynamic programmingDFSBacktrackingNo attempts yetTime limit2sMemory limit64 MB

Problem

Since Krešo started growing chili peppers, N restaurants across Croatia want his peppers so their dishes get real heat. Orders piled up, so Krešo decided to deliver the peppers himself.

The restaurants are numbered 1 to N and are joined by N1N - 1 roads, so a trip between any two restaurants is possible. Krešo starts at restaurant 1. In one unit of time he either drives to an adjacent restaurant or delivers peppers to the restaurant he is standing at. Restaurant i needs AiA_i peppers. A restaurant takes a delivery only once, and that single delivery hands over its whole requirement AiA_i.

Delivering is tiring, so Krešo spends M units of time in total on driving and delivering, then takes a break. Find the largest amount of peppers Krešo can deliver within that time. Assume he always carries an unlimited supply of peppers.

Input

The first line contains two integers N and M, the number of restaurants and the time Krešo plans to spend on delivery. (1N,M5001 \le N, M \le 500)

The second line contains N integers AiA_i, the amount of peppers restaurant i needs. (1Ai1061 \le A_i \le 10^6, 1iN1 \le i \le N)

Each of the next N1N - 1 lines contains two integers U and V, meaning a road joins restaurant U and restaurant V. (1U,VN1 \le U, V \le N, UVU \ne V)

Output

Print on one line the largest amount of peppers Krešo can deliver within the given time.

Hint

Look at the first example. Krešo delivers peppers to restaurant 1 (one unit of time), drives to restaurant 3 (one unit of time), then delivers peppers to restaurant 3 (one unit of time). Two units of time are left, enough to reach restaurant 2 but one unit short of delivering there.