#P4253. [SCOI2015] 小凸玩密室

[SCOI2015] 小凸玩密室

Description

Xiao Tu and Xiao Fang decide to play an escape room. The escape room is a complete binary tree with nn nodes, and each node has a light bulb. You can escape by lighting all bulbs. Each bulb has a weight aia_i, and each edge has a weight bib_i. Lighting the first bulb costs nothing. After that, lighting a new bulb vv costs Du,v×avD_{u,v} \times a_v, where uu is the bulb lit immediately before and Du,vD_{u,v} is the distance from uu to vv 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 nn, the number of nodes.

The second line contains nn integers, the weight aia_i of each node (i=1,2,,ni = 1, 2, \ldots, n).

The third line contains n1n - 1 integers, the weight bib_i of each edge. The ii-th edge connects node i+12\left\lfloor \dfrac{i+1}{2} \right\rfloor to node i+1i + 1 (i=1,2,,n1i = 1, 2, \ldots, n - 1).

Output Format

Output one integer, the minimum total cost.

3
5 1 2
2 1

5

Hint

For 10% of the testdata, 1n101 \leq n \leq 10.

For 20% of the testdata, 1n201 \leq n \leq 20.

For 30% of the testdata, 1n20001 \leq n \leq 2000.

For 100% of the testdata, 1n2×1051 \leq n \leq 2 \times 10^5, 1ai,bi1051 \leq a_i, b_i \leq 10^5.

Translated by ChatGPT 5