#P8677. [蓝桥杯 2018 国 A] 采油

[蓝桥杯 2018 国 A] 采油

Description

LQ Company is a world-famous oil company that supplies high-quality oil to the world.

Recently, LQ Company discovered a large oilfield area in a forest, where nn oil wells can be developed.

LQ Company built n1n-1 roads among these nn wells. Each road connects two wells, does not pass through any other well along the way, and these roads connect all wells.

Building a well requires a large piece of equipment, which is very hard to transport. LQ Company plans to build an air station at one of the wells: first airlift the equipment to the air station, then transport this equipment along the roads they built to construct different wells. After all wells are constructed, the equipment is moved out from the air station.

To reduce transportation trouble, the company requires the total distance traveled by the equipment on the roads to be as short as possible.

During the construction and extraction process, some manpower is needed. The ii-th well requires BiB_i workers for construction, and once the well is completed, it requires SiS_i workers to stay at the well for maintenance.

Of course, if a person participates in constructing a well, they can directly stay to maintain that well, or participate in constructing the next well. However, workers who are maintaining wells cannot participate in the construction of subsequent wells.

Now LQ Company wants to know: what is the minimum possible total path length for transporting the equipment? Under the condition that the total path length is minimized, what is the minimum manpower needed to complete the construction and maintenance of all wells?

Input Format

The first line contains an integer nn, the number of oil wells. The wells are numbered from 11 to nn.

The second line contains nn integers, representing B1,B2,,BnB_1,B_2,\cdots,B_n, separated by single spaces.

The third line contains nn integers, representing S1,S2,,SnS_1,S_2,\cdots,S_n, separated by single spaces.

The next n1n-1 lines describe the roads between wells. The ii-th of these lines contains two integers aa, bb, separated by a single space, meaning that there is a road whose start is i+1i+1, whose end is aa, and whose length is bb. The road is bidirectional: the equipment can be transported from either end to the other. Each road can be used any number of times. The testdata guarantees that any two wells can be connected via the roads.

Output Format

Output two integers separated by a single space: the minimum total distance that the equipment needs to be transported in the optimal plan, and the minimum manpower required under the condition that the total distance is minimized.

6
3 10 20 7 15 9
2 6 10 4 8 7
1 9
1 2
2 5
3 4
3 7
54 38
2
10 20
15 15
1 8
16 30

Hint

[Sample Explanation 2]

There are two plans that achieve the optimum.

Plan 1: Build the air station at well 22. First build well 22, then transport the equipment to well 11 to build well 11, and finally transport the equipment back to well 22.

Plan 2: Build the air station at well 11. First transport the equipment to well 22 to build well 22, then transport the equipment to well 11.

[Constraints]

For 20%20\% of the data: nn does not exceed 1010.

For another 20%20\% of the data: each well has roads directly connecting it to at most two other wells.

For another 10%10\% of the data: there are n1n-1 wells that have only one road connecting them to other wells.

For 100%100\% of the data: 1n1051 \le n \le 10^5, and BB, SS, and cc are all positive integers not exceeding 1000010000.

Time limit: 1 second, 256 MB. Lanqiao Cup 2018, the 9th National Contest.

Translated by ChatGPT 5