Problem:
Score : 400 points

Problem Statement

Given is a rooted tree with N vertices numbered 1 to N.
The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i.

Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0.

Now, the following Q operations will be performed:

Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j.

Find the value of the counter on each vertex after all operations.

Constraints

2 \leq N \leq 2 \times 10^5

1 \leq Q \leq 2 \times 10^5

1 \leq a_i < b_i \leq N

1 \leq p_j \leq N

1 \leq x_j \leq 10^4

The given graph is a tree.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N Q
a_1 b_1
:
a_{N-1} b_{N-1}
p_1 x_1
:
p_Q x_Q

Output

Print the values of the counters on Vertex 1, 2, \ldots, N after all operations, in this order, with spaces in between.

Sample Input 1

4 3
1 2
2 3
2 4
2 10
1 100
3 1

Sample Output 1

100 110 111 110

The tree in this input is as follows:

Each operation changes the values of the counters on the vertices as follows:

Operation 1: Increment by 10 the counter on every vertex contained in the subtree rooted at Vertex 2, that is, Vertex 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 0, 10, 10, 10, respectively.

Operation 2: Increment by 100 the counter on every vertex contained in the subtree rooted at Vertex 1, that is, Vertex 1, 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 110, 110, respectively.

Operation 3: Increment by 1 the counter on every vertex contained in the subtree rooted at Vertex 3, that is, Vertex 3. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 111, 110, respectively.

Sample Input 2

6 2
1 2
1 3
2 4
3 6
2 5
1 10
1 10

Sample Output 2

20 20 20 20 20 20

Solution in JavaScript (node.js v5.12) (judge verdict: Accepted)

module.exports=function(t){var r={};function e(n){if(r[n])return r[n].exports;var i=r[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,e),i.l=!0,i.exports}return e.m=t,e.c=r,e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{enumerable:!0,get:n})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,r){if(1&r&&(t=e(t)),8&r)return t;if(4&r&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(e.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&r&&"string"!=typeof t)for(var i in t)e.d(n,i,function(r){return t[r]}.bind(null,i));return n},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},e.p="",e(e.s=0)}([function(t,r,e){e(1)(e(3).readFileSync("/dev/stdin","UTF-8"))},function(t,r,e){function n(t,r){return function(t){if(Array.isArray(t))return t}(t)||function(t,r){var e=[],n=!0,i=!1,o=void 0;try{for(var u,s=t[Symbol.iterator]();!(n=(u=s.next()).done)&&(e.push(u.value),!r||e.length!==r);n=!0);}catch(t){i=!0,o=t}finally{try{n||null==s.return||s.return()}finally{if(i)throw o}}return e}(t,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var i=e(2);t.exports=function(t){for(var r=t.split("\n"),e=n(r[0].split(" ").map(function(t){return Number(t)}),2),o=e[0],u=e[1],s=new Array(o),a=0;a<o-1;a++){var l=n(r[a+1].split(" ").map(function(t){return Number(t)-1}),2),f=l[0],c=l[1];s[f]||(s[f]=[]),s[c]||(s[c]=[]),s[f].push(c),s[c].push(f)}for(var p=new Array(o).fill(0),d=0;d<u;d++){var v=n(r[d+o].split(" ").map(function(t){return Number(t)}),2),y=v[0],h=v[1];p[y-1]+=h}var m=new i,b=new Array(o).fill(0);for(m.enq(0);m.size>0;){var x=m.deq();b[x]=1;var g=!0,w=!1,j=void 0;try{for(var S,O=s[x][Symbol.iterator]();!(g=(S=O.next()).done);g=!0){var q=S.value;1!=b[q]&&(p[q]+=p[x],m.enq(q))}}catch(t){w=!0,j=t}finally{try{g||null==O.return||O.return()}finally{if(w)throw j}}}console.log(p.join(" "))}},function(t,r,e){"use strict";t.exports=class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1e4;this.size=0,this.items=[],this.ind=0,this.maxGap=t}enq(t){this.size+=1,this.items.push(t),this.items.size-this.ind>this.maxGap&&(this.items=this.items.slice(this.ind))}deq(){var t=this.items[this.ind];return this.size-=1,this.ind+=1,t}}},function(t,r){t.exports=require("fs")}]);