#P4253. [SCOI2015] 小凸玩密室
[SCOI2015] 小凸玩密室
Description
Xiao Tu and Xiao Fang decide to play an escape room. The escape room is a complete binary tree with nodes, and each node has a light bulb. You can escape by lighting all bulbs. Each bulb has a weight , and each edge has a weight . Lighting the first bulb costs nothing. After that, lighting a new bulb costs , where is the bulb lit immediately before and is the distance from to in the tree (the sum of edge weights along the path). During the process, at any time the lit bulbs must be connected. Moreover, once you light a bulb, you must finish lighting all bulbs in its subtree before you may light any bulb outside that subtree. Please tell them the minimum total cost to escape.
Input Format
The first line contains one integer , the number of nodes.
The second line contains integers, the weight of each node ().
The third line contains integers, the weight of each edge. The -th edge connects node to node ().
Output Format
Output one integer, the minimum total cost.
3
5 1 2
2 1
5
Hint
For 10% of the testdata, .
For 20% of the testdata, .
For 30% of the testdata, .
For 100% of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号