시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
4 초 | 1024 MB | 77 | 21 | 20 | 35.088% |
JOI-kun has years of experience of growing vegetables in his home vegetable garden. Now he is planning to manage IOI Farm.
IOI Farm consists of $N$ lands, numbered from $1$ to $N$. There are $N - 1$ roads connecting with lands, numbered from $1$ to $N - 1$. The road $i$ ($1 ≤ i ≤ N - 1$) connects the land $A_i$ and the land $B_i$ bidirectionally. It is possible to move from any land to any other land by passing through roads. There is a sprinkler in every land of IOI Farm. Using a sprinkler, we can spray water on surrounding lands.
JOI-kun is planning to grow JOI millets in IOI Farm. JOI millet is a curious plant. If we give water, the height of a JOI millet changes immediately. But, JOI millet is a weak plant. If the height of a JOI millet becomes larger than or equal to $L$, the top part of length $L$ of the JOI millet is broken immediately. JOI-kun will harvest the broken parts of JOI millets.
In the beginning, JOI-kun plants a JOI millet of height $H_j$ in the land $j$ ($1 ≤ j ≤ N$). After that, for $Q$ days, JOI-kun will take care of the JOI millets everyday. On the $k$-th day ($1 ≤ k ≤ Q$), JOI-kun takes one of the following actions.
Here, the distance from the land $x$ ($1 ≤ x ≤ N$) to the land $y$ ($1 ≤ y ≤ N$) is the minimum number of roads we have to pass through when we move from the land $x$ to the land $y$.
JOI-kun wants to see that the JOI millets are grown up as planned. For this purpose, he wants to calculate the height of a JOI millet measured by each action of Type 2 in advance.
Write a program which, given information of IOI Farm and JOI-kun’s plan, calculates the height of a JOI millet measured by each action of Type 2 taken by JOI-kun.
Read the following data from the standard input. Given values are all integers.
$\begin{align*}& N\,L \\ & A_1 \, B_1 \\ & A_2 \, B_2 \\ & \vdots \\ & A_{N-1} \, B_{N-1} \\ & H_1 \\ & H_2 \\ & \vdots \\ & H_N \\ & Q \\ & \text{(Query }1\text{)} \\ & \text{(Query }2\text{)} \\ & \vdots \\ & \text{(Query }Q\text{)} \end{align*}$
Each $\text{(Query }k\text{)}$ ($1 ≤ k ≤ Q$) consists of space separated integers. Let $T_k$ be the first integer of $\text{(Query }k\text{)}$. The content of this line is one of the following.
For each action of Type 2 (i.e., for each $k$ ($1 ≤ k ≤ Q$) with $T_k = 2$), write the height of a JOI millet in the land $X_k$ measured by the action of Type 2 on the $k$-th day to the standard output, in this order. The outputs should be separated by line breaks.
번호 | 배점 | 제한 |
---|---|---|
1 | 3 | $N ≤ 1\,000$, $Q ≤ 1\,000$. |
2 | 9 | For every $k$ ($1 ≤ k ≤ Q$) with $T_k = 1$, the inequality $D_k ≤ 1$ is satisfied. |
3 | 29 | For every $k$ ($1 ≤ k ≤ Q$) with $T_k = 1$, the inequality $D_k ≤ 2$ is satisfied. |
4 | 12 | For every $k$ ($1 ≤ k ≤ Q$) with $T_k = 1$, the inequality $W_k = 0$ is satisfied. |
5 | 30 | For every $k$ ($1 ≤ k ≤ Q$) with $T_k = 1$, the inequality $W_k = 2$ is satisfied. |
6 | 17 | No additional constraints. |
4 7 1 2 2 3 3 4 1 1 1 1 11 1 2 1 2 1 1 0 2 2 1 2 2 2 3 2 4 1 4 10 2 2 1 2 2 2 3 2 4
4 2 2 1 1 4 4 2
In the beginning, JOI-kun plants a JOI millet of height $1$ in every land.
On the first day, JOI-kun uses the sprinkler of the land $2$. The heights of the JOI millets in the lands $1$, $2$, $3$ (whose distances from the land $2$ are less than or equal to $1$) are multiplied by $2$. After that, the heights of the JOI millets in the lands $1$, $2$, $3$, $4$ are $2$, $2$, $2$, $1$, respectively.
On the second day, JOI-kun uses the sprinkler of the land $1$. The heights of the JOI millets in the land $1$ (whose distance from the land $1$ is less than or equal to $0$) are multiplied by $2$. After that, the heights of the JOI millets in the lands $1$, $2$, $3$, $4$ are $4$, $2$, $2$, $1$, respectively.
On the seventh day, JOI-kun uses the sprinkler of the land $4$. The heights of the JOI millets in the lands $1$, $2$, $3$, $4$ (whose distances from the land $4$ are less than or equal to $10$) are multiplied by $2$. After that, the heights of the JOI millets in the lands $1$, $2$, $3$, $4$ are $8$, $4$, $4$, $2$, respectively. Since the height of the JOI millet in the land $1$ is larger than $7$, the top part of length $7$ is broken immediately. Finally, the heights are $1$, $4$, $4$, $2$.
This sample input satisfies the constraints of Subtasks 1, 5, 6.
6 10 5 6 1 2 1 4 2 6 3 6 9 2 3 4 9 1 10 1 5 1 7 2 4 1 4 1 9 1 5 0 7 2 1 1 1 1 3 1 6 1 4 2 5 2 4 2 3
4 1 4 8 2
On the first day, JOI-kun uses the sprinkler of the land $5$. The heights of the JOI millets in the lands $5$, $6$ (whose distances from the land $5$ are less than or equal to $1$) are multiplied by $7$. After that, the heights of the JOI millets in the lands $5$, $6$ are $63$, $7$, respectively. In the land $5$, the top part of length $10$ of the JOI millet is broken immediately. This process is repeated several times until the height becomes less than $10$. Finally, the heights are $3$, $7$, respectively.
This sample input satisfies the constraints of Subtasks 1, 2, 3, 6.
8 10 1 3 3 5 4 7 6 7 4 5 7 8 2 4 5 8 6 4 6 2 9 3 11 1 2 2 0 2 1 1 6 1 0 2 4 2 6 1 5 2 0 2 8 1 7 2 0 2 6 2 7 2 4
5 0 0 3 0 0 0
This sample input satisfies the constraints of Subtasks 1, 3, 4, 6.