Organization and The Visitors
All submissions for this problem are available.
There are N employees working in an organisation. The organisation is structures in such a way that each Employee has some employees working under him.You are given with the salary of each employee and the employees working under him.Each employee will have exactly one boss.
Now the head of the organisation comes to visit and increases the salary of any employee and the employees working under him by some amount M by watching there good performances of their group.
If the salary of any employee gets increased then the salary of all the employees below him and his employees will also be increased.
There are two types of queries:
1) 0 U M: - Which denotes increase the salary of the employee U and the employees working under him with amount M.
2) 1 U : - Print the salary of the employee U.
The first line of input contains two space separated integers N (no. of employees) and Q (Total queries).
The 2nd line of input contains N space separated integer where ith integer denotes salary of ith employee.
Then there are n-1 lines containing two integers u v which denotes the connection between two employee where u is boss of v.
After there are Q lines which are the queries in the form as explained above.
Output the answer of each 1 type query in a single line.
1<=N<=10^3 1<=Q<=10^3 Subtask 2:
1<=N<=10^5 1<=Q<=10^5 1<=U,V<=N 1<=S<=10^6 1<=M<=10^3
Input: 6 5 100 50 30 25 80 25 1 4 1 5 2 3 4 6 5 2 0 4 25 1 3 1 6 0 1 10 1 6 Output: 30 50 60
Example case 1. ...EXPLANATION:- Initially the organisation is
Query :- 0 4 25
Now salary of 3 is 30 and salary of 6 is 50.
Query:- 0 1 10
Now salary of 6 is 60.
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, CLOJ, COB, FS|
Fetching successful submissions