Skills Assessment
In a company, there are employees. Each employee has a supervisor, except for the company's director, who has no one above them. The company's organizational chart, which is a diagram showing who is the supervisor of whom, resembles a tree structure with the director at the root.
For each employee , we define the "supervisory group" as follows:
- Employee belongs to their own supervisory group and
- for each subordinate of employee , all members of 's supervisory group also belong to 's supervisory group.
This year, the company decided to conduct a skills assessment of its employees by having them take an ability test. Each employee received a score ranging from to .
We aim to answer questions such as: "How many employees in the supervisory group of scored between and (inclusive)?"
To further complicate matters, some employees decided to retake the test, resulting in changes to their scores...
Input:
The first line of the input will contain three natural numbers , and : the number of employees, the maximum score value, and the number of actions your program needs to perform.
The next lines describe the employees, numbered from to . Specifically, the -th line contains two integers and , separated by a space. This means that employee reports to employee and scored in the test. For the company director, who has no supervisor, . Assume that the company's organizational chart defined in these lines is always valid.
The next lines describe an action your program should execute. Actions are of two types, starting either with the letter "" or "", followed by two or three integers respectively, separated by spaces The meaning of the actions is as follows:
- u (update) Employee has retaken the test and scored .
- q (query) Answer the question: How many employees in the group supervised by employee . have scored such that .
Output:
The output should contain one line for each action of type "" (query). Each of these lines should contain, in order, an integer: the answer to the corresponding query.
Constraints:
- .
- .
- .
- Time Limit: sec.
- Memory Limit: MB.
- For test cases with a total value of , it will be , .
- For test cases with a total value of , it will be , i.e. all employees will have received the same score, and the only thing needed is to count them.
- For test cases with a total value of , it will be .
Example of Input - Ouput:
input:
4 4 3
0 1
1 2
1 4
2 3
q 1 2 3
u 4 1
q 2 2 3
output:
2
1
Explanation of the example:
The first question has an answer of because in the group supervised by , there are two employees with scores between and (employee has a score of and employee has a score of ). Then, the score of changes to . The second question now has an answer of because in the group supervised by , there is now only one employee with a score between and (employee himself, who has a score of ).
Comments