| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 7.5 초 | 2048 MB | 32 | 12 | 11 | 40.741% |
JOI Kingdom consists of $N$ cities numbered from 1ドル$ to $N$. There are $N − 1$ one-way roads connecting these cities. Specifically, for each $i = 2, 3, \dots , N,ドル there is a road leading from city $i$ to city $P_i$. Here, it is guaranteed that 1ドル ≤ P_i < i$.
Each of the $N$ cities has a defined danger level. The capital city, city 1ドル,ドル has a danger level of 0ドル$. For city $i$ (2ドル ≤ i ≤ N$), the danger level is defined as the number of roads traversed in the path from city $i$ to city 1ドル$. Due to the structure of JOI Kingdom, there is exactly one unique path from any city $i$ to city 1ドル$.
Currently, there are $K_i$ beavers living in city $i$ (1ドル ≤ i ≤ N$). The president of JOI Kingdom, Bitaro, has planned a beaver relocation program. This relocation plan will be executed over $Q$ days. On the $j$-th day (1ドル ≤ j ≤ Q$), one of the following three types of events will occur:
As Bitaro’s subordinate, you realize that you can compute the number of beavers in each survey event based solely on the relocation plan’s information, without physically visiting the city.
Given the structure of JOI Kingdom, the current number of beavers living in each city, and the details of the relocation plan, write a program to compute the results of each survey event.
Read the following data from the standard input.
$N$
$P_2$ $P_3$ $\cdots$ $P_N$
$K_1$ $K_2$ $\cdots$ $K_N$
$Q$
(Query 1ドル$)
(Query 2ドル$)
$\vdots$
(Query $Q$)
Each (Query $j$) (1ドル ≤ j ≤ Q$) consists of several integers separated by spaces. Let the first integer be $T_j,ドル then the content of this line is as follows:
For each $j$ (1ドル ≤ j ≤ Q$) where $T_j = 3,ドル output the number of beavers in city $B_j$ at that moment, one per line, in order.
Let the maximum danger level of the cities be $D$.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 4 | $D = 1$. |
| 2 | 8 | $N ≤ 20$. |
| 3 | 13 | $D ≤ 20$. |
| 4 | 15 | No queries satisfy $T_j = 2,ドル and at most 5ドル$ queries satisfy $T_j = 3$. |
| 5 | 15 | At most 5ドル$ queries satisfy $T_j = 3$. |
| 6 | 27 | No queries satisfy $T_j = 2$. |
| 7 | 18 | No additional constraints. |
4 1 1 2 1 3 4 3 6 3 1 1 1 0 3 1 3 2 1 2 1 3 2
1 8 0 3
Initially, cities 1ドル,ドル 2ドル,ドル 3ドル,ドル 4ドル$ have 1ドル,ドル 3ドル,ドル 4ドル,ドル 3ドル$ beavers respectively. The danger levels of these cities are 0ドル,ドル 1ドル,ドル 1ドル,ドル 2ドル,ドル respectively.
This input example satisfies the constraints of subtasks 2, 3, 4, 5, 6, 7.
3 1 1 3 1 4 11 2 2 5 1 2 0 3 1 1 1 0 3 1 3 2 2 3 4 3 3 1 1 0 3 3 3 1
3 13 0 4 0 1
Initially, cities 1ドル,ドル 2ドル,ドル 3ドル$ have 3ドル,ドル 1ドル,ドル 4ドル$ beavers, respectively. The danger levels of these cities are 0ドル,ドル 1ドル,ドル 1ドル,ドル respectively.
Subsequent events occur similarly, but their descriptions are omitted.
This input example satisfies the constraints of subtasks 1, 2, 3, 7.
7 1 2 1 3 3 2 5 2 8 9 4 0 5 10 1 3 1 2 4 10 3 2 1 6 3 1 2 0 3 1 3 4 2 5 6 3 5 3 3
6 18 19 6 0
This input example satisfies the constraints of subtasks 2, 3, 5, 7.