Mirko loves cars and he finally managed to start his own car factory! Factory has employees, each of them has exactly one superior (except Mirko - he is by default everybody's superior). Mirko is denoted by number , and the rest of the employees with numbers to .
Every employee can raise or lower the wages of all of his subordinates (both direct subordinates and those lower in the hierarchy tree). Mirko's role is to prevent abuse of such power, so from time to time he wants to know wage of a particular employee.
He is asking you to write a program which will help him monitor wage changes, given a sequence of commands described in the input section.
Remark: at any time, all of the wages will be positive integers and will fit in standard -bit integer type (int
in C/C++, longint
in Pascal).
Input Specification
First line of input contains two space-separated positive integers , number of employees, and , number of wage changes and wage queries.
Next lines contain the information about employees (respectively): starting wage and the identifier of his direct supervisor.
Remark: Mirko has no supervisor, so his line contains only his starting wage.
Next lines contain one of the following:
- employee increases (or decreases in case of a negative ) wage of all his subordinates by the amount ;
- Mirko wants to know the wage of employee .
Output Specification
Output should contain one line for each '2' query in the input - the current wage of the given employee.
Sample Input 1
2 3
5
3 1
p 1 5
u 2
u 1
Sample Output 1
8
5
Sample Input 2
5 5
4
2 1
6 1
7 1
3 4
u 3
p 1 -1
u 3
p 4 5
u 5
Sample Output 2
6
5
7
Sample Input 3
6 7
5
4 1
3 2
7 3
2 3
3 5
p 3 2
p 2 4
u 3
u 6
p 5 -2
u 6
u 1
Sample Output 3
7
9
7
5
Comments
I just found a very similar problem on the Singapore Online Judge: https://codebreaker.xyz/problem/payraise I was able to pass there, but in the Canadian OJ (DMOJ) I am getting MLE on the 10th test case.