Migration Plan
시간 제한7.5초메모리 제한2048 MB
위험도로 정의된 트리 깊이를 기준으로 한 도시 사이에서 비버 무리가 이동하며, 같은 위험도의 모든 비버를 상위 위험도 도시로 옮기는 이주, 한 도시에 비버를 더하는 이민, 한 도시의 비버 수를 묻는 조사를 온라인으로 처리한다.
문제
JOI Kingdom consists of cities numbered from to . There are one-way roads connecting these cities. Specifically, for each , there is a road leading from city to city . Here, it is guaranteed that .
Each of the cities has a defined danger level. The capital city, city , has a danger level of . For city (), the danger level is defined as the number of roads traversed in the path from city to city . Due to the structure of JOI Kingdom, there is exactly one unique path from any city to city .
Currently, there are beavers living in city (). The president of JOI Kingdom, Bitaro, has planned a beaver relocation program. This relocation plan will be executed over days. On the -th day (), one of the following three types of events will occur:
- Relocation: All beavers living in a city with danger level at that moment will move to a city with danger level , which they can reach by traveling along one or more roads from their current city. It is guaranteed that . Due to the structure of JOI Kingdom, the relocation destination for each beaver is uniquely determined.
- Immigration: The number of beavers living in city increases by due to immigration from outside JOI Kingdom.
- Survey: The number of beavers currently living in city is surveyed.
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.
(Query )
(Query )
(Query )
Each (Query ) () consists of several integers separated by spaces. Let the first integer be , then the content of this line is as follows:
- If , the line continues with two integers , in this order. This indicates that on day , a relocation event occurs, where all beavers living in a city with danger level move to a city with danger level that they can reach by traveling along one or more roads from their current city.
- If , the line continues with two integers , in this order. This indicates that on day , an immigration event occurs, increasing the number of beavers in city by .
- If , the line continues with one integer . This indicates that on day , a survey event occurs, where the number of beavers currently living in city is surveyed.
출력
For each () where , output the number of beavers in city at that moment, one per line, in order.
제한
- .
- ().
- ().
- .
- is either , , or ().
- If , then ().
- If , then , ().
- If , then ().
- At least one () satisfies .
- All input values are integers.