#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 to be activated. Nevertheless, SHTSC does not need to activate all blocks manually, because once a fusion block is activated, it sends 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 , indicating that there are fusion blocks, numbered to .
The second line contains integers, representing in order.
The third line contains integers, representing in order.
Each of the following lines contains two integers , indicating that fusion blocks and 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 # | Additional constraints | ||
|---|---|---|---|
| 1 | |||
| 2 | |||
| 3 | |||
| 4 | - | ||
| 5 | |||
| 6 | - | ||
| 7 | |||
| 8 | - | ||
| 9 | |||
| 10 | |||
| 11 | |||
| 12 | are all equal | ||
| 13 | - | ||
| 14 | are all equal | ||
| 15 | - | ||
| 16 | |||
| 17 | are all equal | ||
| 18 | - | ||
| 19 | |||
| 20 |
For all testdata, it is guaranteed that .
Translated by ChatGPT 5
京公网安备 11011102002149号