|
||||||||||
NetworkTime Limit: 2000/10000 MS (Java/Others) Memory Limit: 98304/98304 K (Java/Others)Total Submission(s): 163 Accepted Submission(s): 3 Problem Description There is a network which is a completely binary tree. In the network, there are 2N users numbered from 1, 2, 3, 4, ... 2N, which are the leaves in the network-tree. For example, Figure 1 is a network-tree. In the tree, there are 8 users (leaf nodes) and 7 transmitters (gray nodes). Using network-tree means that you have to pay a cost for it. The charging way is so interesting, named "pair charging". The cost you must pay is the sum of cost from every pair of user i and user j ( 1 ¡Ü i < j ¡Ü 2N). Every user can choose mode A or mode B to pay for the charge. For every two users i, j (1 ¡Ü i < j ¡Ü 2N), first find their LCA (The Least Common Ancestors): Transmitter P. Then count the number of mode A users in the tree of ROOT transmitter P, so do mode B. Next, let's name the number nA and nB and at last charge the cost. f[i][j] is the flow between user i and user j. The charging way is followed: At first, every user has an initial mode, A or B. However, they want to reduce the cost, so a part of them would change the mode from A to B, or from B to A. Every change will have an extra cost. If user i changes his mode, he will pay Ci cost. Now, you should find the minimum cost, that is, the sum of the cost having to pay for and the extra cost of changing mode. Input First line, an integer N (N ¡Ü 10). Sencond line, 2N integers, ith integer stands for ith user's initial mode. 0 is mode A, 1 is mode B. Third line, 2N integers, ith integer stands for Ci, the cost that ith user changes his mode. (0 ¡Ü Ci ¡Ü 500 000) Next 2N - 1 line, describe the flow of every pair of users. The i + 3 th line's (in the whole input) j row's integer standing for the f[i][j + i]. (1 ¡Ü i ¡Ü 2^N ,1 ¡Ü j ¡Ü 2^N - i, 0 ¡Ü f[i][j] ¡Ü 500). Output Only a single integer, standing for the minimum cost above. Sample Input
Sample Output
Source | ||||||||||
|