#P4629. [SHOI2015] 聚变反应炉

[SHOI2015] 聚变反应炉

Description

The inventor SHTSC, who once created the parts assembler, has now revealed his new invention: a fusion reactor—a mysterious device that can produce a large amount of clean energy.

As is well known, there are two difficulties in harnessing energy from nuclear fusion: one is controlling the intensity of the fusion reaction, and the other is activating the fusion reaction using as little energy as possible. SHTSC has perfectly solved the first problem. A fusion reactor consists of several interconnected fusion blocks. To ensure controllability, SHTSC guarantees that any two fusion blocks can reach each other via links, and no fusion block can return to itself without repeating an edge. In other words, the links form a tree.

However, the second problem is not fully solved. In his design, each fusion block requires a certain initial energy did_i to be activated. Nevertheless, SHTSC does not need to activate all blocks manually, because once a fusion block is activated, it sends cic_i units of energy to all directly connected fusion blocks that have not yet been activated. In this way, fusion blocks activated later can be activated with lower initial energy, or even without any additional external energy, thereby reducing the total activation energy. Given a fusion reactor, find the minimum amount of energy required to activate all fusion blocks.

Input Format

The first line contains an integer nn, indicating that there are nn fusion blocks, numbered 11 to nn.
The second line contains nn integers, representing did_i in order.
The third line contains nn integers, representing cic_i in order.
Each of the following n1n - 1 lines contains two integers u,vu, v, indicating that fusion blocks uu and vv are connected.

Output Format

Output a single integer on one line, indicating the minimum number of energy units required to activate all fusion blocks.

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

Hint

Case # max{ci}\max\{c_i\} nn Additional constraints
1 =1= 1 10\leq 10 ci=1c_i = 1
2 100\leq 100
3 200\leq 200
4 =0= 0 10\leq 10 -
5 =1= 1 200\leq 200 ci=1c_i = 1
6 -
7 100000\leq 100000 ci=1c_i = 1
8 =0= 0 -
9 =1= 1
10
11 5\leq 5 20\leq 20
12 cic_i are all equal
13 200\leq 200 -
14 cic_i are all equal
15 -
16
17 2000\leq 2000 cic_i are all equal
18 -
19
20

For all testdata, it is guaranteed that 1di,di1091 \le d_i, \sum d_i \le 10^9.

Translated by ChatGPT 5