#P8581. [CoE R5] X 细胞
[CoE R5] X 细胞
Problem Description
Brief statement
A rooted tree is a directed graph with a special vertex called the root. From the root, there is a unique directed path to every other vertex in the graph. By convention, vertices in a rooted tree are called nodes. A subtree is a subgraph of a rooted tree that is itself a rooted tree whose root is some node in . In a rooted tree, if there is an edge from node to node , then node is called the parent of node , and node is called a child of node . A node with no children is called a leaf node.
Given a rooted tree , the -th node has weights and .
Let be a subtree of , and let be the set of all subtrees of rooted at node .
-
Define , where and .
-
Define to be a subtree rooted at node such that , and among those, it has the maximum number of nodes.
-
Define : for a node in , let its parent be . Then if and only if but .
Given a rooted tree with nodes, let the root be , and perform the following operations:
() Put the root node into a node set , i.e., initially set .
() Choose any element in and let it be . Determine . For each node , set .
() Remove from , and set .
() If , stop; otherwise go to step ().
Each execution of step () determines a subtree of . Suppose step () is executed a total of times when the process ends. Let the subtree determined in the -th execution of step () be . Minimize the following value :
$$W = 1 \times \lceil r(K_1) \rceil + 2 \times \lceil r(K_2) \rceil + \cdots + m \times \lceil r(K_m) \rceil = \sum_{i = 1}^{m}i \times \lceil r(K_i) \rceil$$denotes the set of all positive integers, and denotes the smallest integer not less than .
Original statement
cells are an ancient life form from planet in the Andromeda galaxy.
Initially, there is only cell, and cells can produce descendant cells by direct division. For an cell , if it produces a direct descendant cell , then cell is called the mother cell of cell , and cell is called a child cell of .
Note that the definitions of mother cell and child cell are not transitive. Suppose cell produces a direct descendant cell , and cell produces a direct descendant cell . Then is a child cell of , and is a child cell of , but is not a child cell of .
Each cell has a vitality value and a volume . For convenience, people define a mutation index for cells:
This index measures how well an cell adapts to the environment. The lower the mutation index, the higher the probability that the cell survives.
It has been found that when an cell receives a certain specific external stimulus, it will activate and begin a process called assimilation to transform into a cell. Before assimilation starts, the activated cell changes its state into a cell. The cell continuously absorbs its child cells and fuses with them, making the child cell become part of the cell.
After fusion, the vitality value and volume of the cell become the sums of those before fusion. That is, suppose cells fuse into one cell, and these cells have vitality values and volumes , , …, and , , …, respectively. After fusion, the cell has vitality value , volume , and mutation index .
During assimilation, the cell follows these rules:
- If a child cell has a mother cell that has not yet been assimilated, then the child cell will not be assimilated.
- Make the mutation index of the cell as small as possible, and assimilate as many cells as possible.
When the cell can no longer assimilate more cells, it stops assimilating, transforms into a cell, and releases pheromones (the vitality value and volume do not change before and after the state change). The pheromone has the following effect: let the mutation index of the resulting cell be . If an unassimilated child cell has a mother cell that is assimilated by this cell, then the vitality value of cell increases by ( denotes the smallest integer not less than ).
Note that when the assimilation process ends, the mutation index of the cell is required to be as small as possible, but during the assimilation process, the mutation index of the cell does not need to remain minimal at all times (see input ).
Researchers need to use a special device to produce the specific external stimulus that activates cells. Each use of the device consumes a certain amount of activator. The amount of activator consumed is computed by:
where is the usage index of the device (starting from ), and is the mutation index of the cell finally produced by this activation.
Because mother cells secrete pheromones that prevent child cells from being activated, one can only choose an cell that has no mother cell, or whose mother cell has already been assimilated, as the target of the specific external stimulus, so that it activates and begins assimilation.
Given the relationships among all cells and their vitality values and volumes, and since activators are very hard to produce, you now need to design an optimal activation order plan for cells so that all cells transform into cells while the total activator consumption is minimized.
You only need to output this minimum value.
Input Format
The first line contains an integer , representing the number of cells.
The next line contains integers, in order representing the mother cell index of cells numbered .
The next line contains integers, in order representing the vitality value of the cell numbered .
The next line contains integers, in order representing the volume of the cell numbered .
The initial cell is numbered .
Input format corresponding to the brief statement:
The first line contains an integer , representing the number of nodes in the rooted tree.
The next line contains integers, in order representing the parent index of nodes numbered .
The next line contains integers, in order representing the weight of the node numbered .
The next line contains integers, in order representing the weight of the node numbered .
The root node is numbered .
Output Format
Output one integer, representing the minimum total activator consumption needed to make all cells transform into cells.
Output format corresponding to the brief statement:
Output one integer, representing the minimum value of .
3
1 2
5 7 12
1 1 10
2
3
1 1
2 2 12
2 3 4
9
5
1 2 2 1
1 7 10 20 9
1 1 1 1 1
223
12
1 2 3 1 5 6 7 1 9 10 11
4 10 2 1 50 1 20 9 40 2 15 10
1 1 1 1 1 1 1 1 1 1 1 1
124
Hint
Sample explanation
Input :
-
Activate cell , assimilate cells and . The resulting cell has vitality value , volume , and mutation index .
-
The minimum activator consumption for the -st activation is $c_1 = t \times \lceil d_z \rceil = 1 \times \lceil \frac {24}{12} \rceil = 1 \times 2 = 2$.
-
Initially, the cell’s mutation index is . After assimilating cell , the mutation index is . After assimilating cell , the mutation index becomes . This shows that during assimilation, the cell’s mutation index does not need to stay minimal at all times; it only needs to be minimal when it finally stops assimilating and transforms into a cell.
Input :
-
Activate cell , assimilate cell . The resulting cell has vitality value , volume , mutation index . The activator consumption for this activation is $c_1 = t \times \lceil d_z \rceil= 1 \times \lceil \frac {4}{5} \rceil = 1 \times 1 = 1$. This cell releases pheromones that increase the vitality value of cell by , so the vitality value of cell becomes .
-
Activate cell , assimilate no other cells. The resulting cell has vitality value , volume , mutation index . The activator consumption for this activation is $c_2 = t \times \lceil d_z \rceil = 2 \times \lceil \frac {13}{4} \rceil= 2 \times 4 = 8$.
-
The minimum total activator consumption for activations is .
Input :
-
Activate cell , assimilate no other cells. The resulting cell has vitality value , volume , mutation index . The total activator consumption is $c_1 = t \times \lceil d_z \rceil = 1 \times \lceil 1 \rceil = 1$. The cell releases pheromones, increasing the vitality values of cells and by each, so their current vitality values are and .
-
Activate cell , assimilate no other cells. The resulting cell has vitality value , volume , mutation index . The total activator consumption is $c_2 = t \times \lceil d_z \rceil = 2 \times \lceil 8 \rceil = 16$. The cell releases pheromones, increasing the vitality values of cells and by each, so their current vitality values are and .
-
Activate cell , assimilate no other cells. The resulting cell has vitality value , volume , mutation index . The total activator consumption is $c_3 = t \times \lceil d_z \rceil = 3 \times \lceil 28 \rceil = 84$.
-
Activate cell , assimilate no other cells. The resulting cell has vitality value , volume , mutation index . The total activator consumption is $c_4 = t \times \lceil d_z \rceil = 4 \times \lceil 18 \rceil = 72$.
-
Activate cell , assimilate no other cells. The resulting cell has vitality value , volume , mutation index . The total activator consumption is $c_5 = t \times \lceil d_z \rceil = 5 \times \lceil 10 \rceil = 50$.
-
The minimum total activator consumption for activations is $c_1 + c_2 + c_3 + c_4 + c_5 = 1 + 16 + 84 + 72 + 50 = 223$.
Input :
-
Activate cell , assimilate no other cells. The resulting cell has mutation index . It releases pheromones that increase the vitality values of cells , , and by . The activator consumption is $c_1 = 1 \times \lceil \frac {4}{1} \rceil = 1 \times 4 = 4$.
-
Activate cell , assimilate cells , , and . The resulting cell has mutation index . The activator consumption is $c_2 = 2 \times \lceil \frac {84}{4} \rceil = 2 \times 21 = 42$.
-
Activate cell , assimilate cells , , and . The resulting cell has mutation index . The activator consumption is $c_3 = 3 \times \lceil \frac {71}{4} \rceil = 3 \times 18 = 54$.
-
Activate cell , assimilate cells and . The resulting cell has mutation index . The activator consumption is $c_4 = 4 \times \lceil \frac {17}{3} \rceil = 4 \times 6 = 24$.
-
The minimum total activator consumption for activations is .
Constraints
This problem uses bundled testdata. Some subtask input files are large, so please use an appropriate input method.
| Subtask | Points | Special Property | Time Limit | Memory Limit | Dependencies | |
|---|---|---|---|---|---|---|
- Special property : the rooted tree corresponds to a star graph. , .
- Special property : the rooted tree corresponds to a directed chain. , .
- Special property : the data is randomly generated. , is a random integer chosen from . are random integers chosen from .
For of the data, , , , and the answer does not exceed .
Translated by ChatGPT 5