#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 shops on the street, and the roads between them form a tree.
Shop sells only item type . Xiaomiao’s preference value for this item is , the price is , and the stock is . However, the shopping street has a strange rule: if you buy things at shops and , and there is a shop on the path from to , then you must also buy something at shop . Xiaocong has 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 , the number of test cases.
For each test case:
The first line contains two positive integers .
The second line contains non-negative integers .
The third line contains positive integers .
The fourth line contains positive integers .
The next lines each contain two positive integers , indicating that there is a road between and .
Output Format
Output 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 , , , , , .
Notes
Source: BZOJ4182.
Translated by ChatGPT 5
京公网安备 11011102002149号