Macht of the Lemon Scent, Denken's teacher and one of the Seven Sages of Destruction. He is famous for his magic that turns everything into lemons. The great mage Frieren must dispel Macht's magic to restore Denken's hometown, which has been turned into lemons.
Macht's magic circle consists of vertices numbered from and is in the form of a tree with root . Each edge is a directed edge pointing from a child to its parent. The -th edge is a directed edge pointing from vertex to vertex with a capacity of .
For Frieren to successfully dispel the magic, she must find the minimum capacity among all edges. That is, she must find the minimum value of . However, Frieren only knows , , and . She does not know . Therefore, she must obtain information through mana manipulation.
Frieren can manipulate mana up to times, and a single manipulation is performed as follows.
Right after the manipulation, , the amount of mana flowing through vertex is calculated recursively as follows.
Here, means the edge directed from to , and is the capacity of that edge.
After the manipulation is over, Frieren can only know : the amount of mana flowing through the root vertex . In addition, each mana manipulation is performed independently of each other. In other words, the magic circle is immediately restored to its original state after the manipulation is over.
Before implementing the functions, you must include the "macht.h" header file using #include "macht.h".
You must implement the following function.
void unravel(std::vector U, std::vector V)
trigger function below.long long trigger(std::vector R, std::vector F);
Consider the following function call.
unravel(3, [0, 0], [1, 2])
The following is one of the possible sequences of function calls.
Called function | Returned value |
| |
| |
The input format for the sample grader is as follows.
Help Frieren dispel Macht's magic by finding the minimum capacity among all edges.
void answer(int min_W);
| 2 | 17 | , (). |
| 3 | 21 | (). |
| 4 | 42 | . |
| 5 | 10 | No additional constraints. |
|
From the result of the second trigger call, it can be seen that the weight of the -st edge (the edge connecting vertex and ) is exactly .
Also, by combining this information with the result of the first trigger call, it can be seen that the weight of the -th edge (the edge connecting vertex and ) must be or more. Otherwise, the value of the mana flowing to the root would have been less than .
Therefore, it can be confirmed that the minimum capacity among all edges is .
The sample grader outputs the following.
trigger function was calledanswer functionNote that the sample grader may differ from the grader used in actual judging.