|
|||
A Job for a SlicerYou are a slicer (hacker) on board of a rebel cruiser with the mission of freeing an essential ally of the Galactic Empire, but to do that, you have to get access to the main terminal using a special card. The terminal has an internal algorithmic problem and a couple of some input tests, which are daily randomly generated. The terminal expects to get the same output from its internal code and the card's code. You have just a blank card and the statement for the algorithmic problem that must be solved to print the code on the card. The statement sounds like this: You are given a rooted tree, where node 1 is the root. The tree has N nodes, and each node has an initial value of 0. You are also given Q queries of 3 types:
Input SpecificationThe first line contains a single number N, which represents the number of nodes (2 ≤ N ≤ 100 000). Each of the next N – 1 lines contains two numbers separated by a space: a and b, which means that there is an edge between node a and node b. The next line contains a number Q, which represents the number of queries (1 ≤ Q ≤ 100 000). Each of the next Q lines contains one of the following types of queries mentioned above:
Output SpecificationThe output should contain a single number for each query of type 2 on a different line, indicating the value of node x. Sample Input
Output for Sample Input
Explanation
As it can be seen here, the answer for the last five queries in order are 6, 6, 3, 3, 3. |
|||
University of Debrecen; Faculty of Informatics; v. 09/30/2024 |