News

아직 제출이 없습니다시간 제한2초메모리 제한1024 MB

문제

Deni is the boss of a company with NN workers, numbered from 11 to NN. The company structure is strictly hierarchical – every worker (except number 11) has exactly one direct supervisor. So, every worker has 11 or more subordinates (direct and indirect) including himself. For example, worker 11 has exactly NN subordinates, including himself. Of course, there isn’t a situation where some subordinate of a worker is his direct supervisor. For some worker xx, we will call xx a 00-level subordinate. Then, his direct subordinates will be called 11-level subordinates of xx. All of their direct subordinates (which are indirect subordinates of xx) will be called 22-level subordinates of xx and so on.

There is a breaking piece of news that is known by some of the workers. Deni wants to inform all of the company employees. So, multiple times she chooses worker xx and number kk, and tells the news to all 00-level, 11-level (if they exist), …, kk-level (if they exist) subordinates of xx. We will call all these subordinates, kk-subordinates of xx. The problem with this type of announcement is that most of the time, many chosen subordinates already know the piece of news. That’s why Deni wants a system that can tell her the number of workers among all the kk-subordinates of xx that have already learned about the news. Write a program that can help her.

입력

From the first line of the standard input read one integer NN – the number of workers in Deni’s company. From each of the next N1N-1 lines read two integers xx and yy, which show that the worker yy is a direct subordinate to the worker xx. From the next line read NN integers: b_1b\_1, b_2b\_2, …, b_Nb\_N, where b_ib\_i is 11, if the worker ii knows the news at the beginning and 00 otherwise. From the next line read one integer QQ – the number of queries. From each of the last QQ lines, read queries of two types:

  • type 11 (news announcement query): 11 xx kk – Deni tells the news to all the kk-subordinates of xx
  • type 22 (question query): 22 xx kk – Deni asks for the number of the workers that know the news among the kk-subordinates of xx

출력

For every query of type 22, on separate lines in the same order as in the input, write one integer – the answer for the corresponding question.

제한

  • 2N2×1052 ≤ N ≤ 2 × 10^5
  • 1Q2×1051 ≤ Q ≤ 2 × 10^5
  • 0kN0 ≤ k ≤ N

힌트

The above picture shows the hierarchy of the company and the workers that know the news at the beginning are colored in orange.

For the first query 22 44 44:

The 00-level subordinate of worker 44 is 44, the 11-level subordinates of worker 44 are workers 77 and 88, the 22-level subordinates of worker 44 are 99 and 1010 and there are no 33-level and 44-level subordinates of worker 44. Workers 44, 88 and 1010 know the news, so the answer to this question query is 33.

For query 11 44 11:

The 11-subordinates of worker 44 are workers 44, 77 and 88. Workers 44 and 88 already know the news, so only worker 77 learns the news at this time.

For the second query 22 44 44:

The 44-subordinates of worker 44 are 44, 77, 88, 99 and 1010. Workers 44, 77, 88 and 1010 know the news, so the answer to the query this time is 44.