#P6326. Shopping

Shopping

Description

Xiaomiao’s birthday is coming soon. To prepare a gift for Xiaomiao, Xiaocong excitedly came to the shopping street. There are nn shops on the street, and the roads between them form a tree.

Shop ii sells only item type ii. Xiaomiao’s preference value for this item is wiw_i, the price is cic_i, and the stock is did_i. However, the shopping street has a strange rule: if you buy things at shops uu and vv, and there is a shop pp on the path from uu to vv, then you must also buy something at shop pp. Xiaocong has mm yuan. He wants to make Xiaomiao as happy as possible, so he wants to maximize the sum of preference values of the items he buys.

This small problem is of course easy for Xiaocong, but he has no computer with him. So he called you, a fellow OI contestant. Can you help him?

Input Format

The first line contains a positive integer TT, the number of test cases.

For each test case:

The first line contains two positive integers n,mn, m.

The second line contains nn non-negative integers w1,w2wnw_1, w_2 \ldots w_n.

The third line contains nn positive integers c1,c2cnc_1, c_2 \ldots c_n.

The fourth line contains nn positive integers d1,d2dnd_1, d_2 \ldots d_n.

The next n1n - 1 lines each contain two positive integers u,vu, v, indicating that there is a road between uu and vv.

Output Format

Output TT lines in total. Each line contains one integer, the maximum possible sum of preference values.

1
3 2
1 2 3
1 1 1
1 2 1
1 2
1 3
4

Hint

Constraints

For all test points, it is guaranteed that 1n5001 \le n \le 500, 1m40001 \le m \le 4000, 1T51 \le T \le 5, 0wi40000 \le w_i \le 4000, 1cim1 \le c_i \le m, 1di25001 \le d_i \le 2500.

Notes

Source: BZOJ4182.

Translated by ChatGPT 5