In the event of technical difficulties with Szkopuł, please contact us via email at email@example.com.
If you are familiar with IRC chat, the support team is also reachable on PIRC network (
#szkopul channel. If you are not, just use email.
Please do not ask us things like "how to solve task XYZ?".
Please remember that the support team has to sleep sometimes or go to work in real life.
Byteasar has designed a supercomputer of novel architecture. It may comprise of many (identical) processing units. Each processing unit can execute a single instruction per time unit.
The programs for this computer are not sequential but rather have a tree structure. Each instruction may have zero, one, or multiple subsequent instructions, for which it is the parent instruction.
The instructions of the program can be executed in parallel on all available processing units. Moreover, they can be executed in many orders: the only restriction is that an instruction cannot be executed unless its parent instruction has been executed before. For example, as many subsequent instructions of an instruction that has been executed already can be executed in parallel as there are processing units.
Byteasar has a certain program to run. Since he likes utilizing his resources optimally, he is wondering how the number of processing units would affect the running time. He asks you to determine, for a given program and number of processing units, the minimum execution time of the program on a supercomputer with this many processing units.
In the first line of standard input, there are two integers, and (), separated by a single space, that specify the number of instructions in Byteasar's program and the number of running time queries (for different numbers of processing units).
In the second line of input, there is a sequence of integers, (), separated by single spaces: is the number of processing units in Byteasar's -th query.
In the third and last input line, there is a sequence of integers, (), separated by single spaces: specifies the number of the parent instruction of the instruction number . The instructions are numbered with successive integers from 1 to , where the instruction no. 1 is the first instruction of the program.
In tests worth 35% of the total score the condition , holds. Moreover, in a subset of those worth 20% of the total score , holds in addition.
Your program should print one line consisting of integers, separated by single spaces, to the standard output: the -th of these numbers should specify the minimum execution time of the program on a supercomputer with processing units.
For the input data:
20 1 3 1 1 1 3 4 3 2 8 6 9 10 12 12 13 14 11 11 11 11
the correct result is:
The program can be executed as follows:
Sample grading tests:
Task author: Michal Wlodarczyk.<Submit a solution> [0/100]