| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 7.5 초 | 2048 MB | 44 | 16 | 15 | 38.462% |
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.