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-----
4 3
1 2
2 3
2 4
2 10
1 100
3 1

-----Sample Output-----
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.

Difficulty: interview

Starter code:

Solutions:
import sys
sys.setrecursionlimit(10**7)
 
N, Q = list(map(int, input().split()))
root = [[] for _ in range(N)]
ans = [0]*N
 
for _ in range(N-1):
  a,b=list(map(int, input().split()))
  a,b=a-1,b-1
  root[a].append(b)
  root[b].append(a)

for _ in range(Q):
  p,x=list(map(int, input().split()))
  ans[p-1]+=x
  
visited=[False]*N
def dfs(v):
  visited[v] = True
  for go in root[v]:
    if visited[go]:
      continue
    ans[go] += ans[v]
    dfs(go)

dfs(0)
print((*ans))


import sys
sys.setrecursionlimit(10 ** 6)

def solve():
    N, Q = list(map(int, input().split()))
    graph = [[] for _ in range(N)]
    for i in range(N - 1):
        a, b = [int(x) - 1 for x in input().split()]
        graph[a].append(b)
        graph[b].append(a)
    ans = [0] * N
    for i in range(Q):
        p, x = list(map(int, input().split()))
        p -= 1
        ans[p] += x
    def dfs(cur, pre):
        for to in graph[cur]:
            if to == pre:
                continue
            ans[to] += ans[cur]
            dfs(to, cur)
    dfs(0, -1)
    print((*ans))
    return

solve()


def main():
    n,q=map(int,input().split())
    ab=[list(map(int,input().split())) for _ in range(n-1)]
    tree=[list() for _ in range(n)]
    score=[0]*n
    for a,b in ab:
        a,b=a-1,b-1
        tree[a].append(b)
        tree[b].append(a)
    e = [0]
    while len(e) > 0:
        i = e.pop()
        for j in tree[i]:
            tree[j].remove(i)
            e.append(j)
    px=[list(map(int,input().split())) for _ in range(q)]
    for p,x in px:
        p-=1
        score[p]+=x
    add(tree,score)
    print(*score)

def add(tree,score):
    s=tree[0][:]
    for i in s:
        score[i] += score[0]
    while len(s)>0:
        t = s.pop()
        for i in tree[t]:
            s.append(i)
            score[i] += score[t]

def __starting_point():
    main()
__starting_point()

import collections,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,Q = LI()
ab = [LI() for _ in [None]*(N-1)]
px = [LI() for _ in [None]*(Q)]
ans = [0]*(N+1) #1_indexed
graph = {i:collections.deque() for i in range(1,N+1)} #1_indexed
for a,b in ab:
        graph[a].append(b)
        graph[b].append(a)
for p,x in px:
    ans[p] += x
seen = [0]*(N+1) #1_indexed
stack = []
def dfs():
    seen[1] = 1
    stack.append(1)
    while stack:
        s = stack.pop()
        if not graph[s]:
            continue
        for j in range(len(graph[s])):
            g_NO = graph[s].popleft()
            if seen[g_NO]:
                continue
            seen[g_NO] = 1
            stack.append(g_NO)
            ans[g_NO] += ans[s]
dfs()
print(*ans[1:])

import sys
sys.setrecursionlimit(10**9)

N,Q=map(int,input().split())
T=[[] for _ in range(N)]
for _ in range(N-1):
  a,b=map(int,input().split())
  a-=1;b-=1
  T[a].append(b)
  T[b].append(a)

V=[0]*N
for _ in range(Q):
  p,x=map(int,input().split())
  V[p-1]+=x
  
def dfs(now,prev=-1):
  for next in T[now]:
    if next!=prev:
      V[next]+=V[now]
      dfs(next,now)

dfs(0)
print(*V)

from collections import defaultdict
import sys
sys.setrecursionlimit(10 ** 6)

n, q = list(map(int, input().split()))
G = [[]*n for i in range(n)]
for _ in range(n-1):
    a, b = list(map(int, input().split()))
    G[a-1].append(b-1)
    G[b-1].append(a-1)


done = [False]*n
points = [0]*n
d = defaultdict(lambda: 0)

for _ in range(q):
    a, b = list(map(int, input().split()))
    d[a-1] += b


def dfs(i, cnt):
    cnt += d[i]
    points[i] += cnt
    done[i] = True
    for j in G[i]:
        if not done[j]:
            dfs(j, cnt)


dfs(0, 0)
print((*points))


N,Q = map(int,input().split())
f = [[] for i in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    f[a-1].append(b-1)
    f[b-1].append(a-1)
ans = [0] * N
for i in range(Q):
    p,x = map(int,input().split())
    ans[p-1] += x
from collections import deque
d = deque()
d.append(0)
root = [-1]*N
root[0] = 0
while len(d) > 0:
    z = d.popleft()
    for i in f[z]:
        if root[i] == -1:
            root[i] = z
            ans[i] += ans[z]
            d.append(i)
print(*ans)

import sys
sys.setrecursionlimit(1<<30)
def dfs(x):
    for y in edges[x]:
        if y != parent[x]:
            parent[y] = x
            count[y] += count[x]
            dfs(y)

N, Q = map(int, input().split())
edges = [[] for _ in range(N+1)]
count = [0]*(N+1)
for i in range(N-1):
    a, b = map(int, input().split())
    edges[a].append(b)
    edges[b].append(a)
for i in range(Q):
    p, x = map(int, input().split())
    count[p] += x

parent = [-1]*(N+1)
dfs(1)
print(*count[1:])

def abc138d_ki():
    import heapq
    n, q = map(int, input().split())
    cnt = [0] * n
    graph = [[] for _ in range(n)]
    for _ in range(n - 1):
        a, b = map(int, input().split())
        graph[a - 1].append(b - 1)
        graph[b - 1].append(a - 1)
    for _ in range(q):
        p, x = map(int, input().split())
        cnt[p - 1] += x
    qu = [(0, 0)]
    heapq.heapify(qu)
    check = [False] * n
    while len(qu) != 0:
        h, no = heapq.heappop(qu)
        check[no] = True
        for nxt in graph[no]:
            if not check[nxt]:
                cnt[nxt] += cnt[no]
                heapq.heappush(qu, (h + 1, nxt))
    for c in cnt:
        print(c, end=' ')


abc138d_ki()

import sys
sys.setrecursionlimit(10**9) #再帰の上限指定
# 木構造の標準入力
N,Q = list(map(int,input().split()))
T=[[] for _ in range(N)]
for _ in range(N-1):
  a,b=list(map(int,input().split()))
  a-=1;b-=1
  T[a].append(b)
  T[b].append(a)

# 入力例1のとき、繋がる頂点のリスト [[1], [0, 2, 3], [1], [1]]
# 足算部分の標準入力
V=[0]*N
for _ in range(Q):
  p,x=list(map(int,input().split()))
  V[p-1]+=x
# 入力例1のとき、各ノード以下に足す値 [100, 10, 1, 0]
def dfs(now,prev=-1):
  for next in T[now]:
    if next!=prev:# 親じゃなければ、(子であれば)足し算する
      V[next]+=V[now]
      dfs(next,now)

dfs(0)
"""
入力例1のとき
dfs(0,-1)→dfs(1,0)→dfs(2,1)
                  →dfs(3,1)
"""
print((*V))


from collections import deque
N, Q = list(map(int, input().split()))
tree = [[] for _ in range(N+1)]
counter = [0]*(N+1)
for i in range(N-1):
    a, b = list(map(int, input().split()))
    tree[a].append(b)
    tree[b].append(a)
for i in range(Q):
    p, x = list(map(int, input().split()))
    counter[p] += x
parent = [-1]*(N+1)
d = deque([1])

while d:
    a = d.popleft()
    for b in tree[a]:
        if parent[a] != b:
            parent[b] = a
            counter[b] += counter[a]
            d.append(b)

print((*counter[1:]))


from collections import deque


def main():
  n,q=map(int,input().split())
  node=[[]*n for i in range(n)]
  for i in range(n-1):
    a,b=map(lambda x:int(x)-1,input().split())
    node[b].append(a)
    node[a].append(b)
  
  ans=[0]*n
  for i in range(q):
    p,x=map(int,input().split())
    p-=1
    ans[p]+=x

  root=[0]*n
  edge=[[]*n for i in range(n)]
  root[0]=0
  q=deque([0])
  visited=[False]*n
  visited[0]=True
  
  while q:
    r=q.popleft()
    for e in node[r]:
      if not visited[e]:
        visited[e]=True
        q.append(e)
        root[e]=r
        edge[r].append(e)
  
  
  p=[0]*n
  q=deque(edge[0])
  visited=[False]*n
  while q:
    e=q.popleft()
    p[e]=p[root[e]]+1
    for e2 in edge[e]:
      if not visited[e2]:
        visited[e2]=True
        q.append(e2)
  
  p=sorted(enumerate(p), key=lambda x:x[1])
  for i in range(1,n):
    e=p[i][0]
    r=root[e]
    ans[e]+=ans[r]
    
  print(*ans,sep=' ')


def __starting_point():
  main()
__starting_point()

import sys
import math

#https://atcoder.jp/contests/agc008/submissions/15248942
sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

counts = []

class Node:
    def __init__(self):
        self.edge = []
        self.count = 0

def dfs(tree,node,p_node,p_count):
    count = tree[node].count + p_count
    counts[node] = count
    for x in tree[node].edge:
        if x == p_node:
            continue
        dfs(tree,x,node,count)

N,Q = inm()

tree = []
for _ in range(N):
    tree.append(Node())

#node = Node()
#tree = [node]*N

for _ in range(N-1):
    a,b = inm()
    tree[a-1].edge.append(b-1)
    tree[b-1].edge.append(a-1)

for _ in range(Q):
    p,x = inm()
    tree[p-1].count += x

for _ in range(N):
    counts.append(0)

#for i in range(N):
#    print(tree[i].edge)
#    print(tree[i].count)


dfs(tree,0,-1,0)

counts_str = [str(n) for n in counts]
s = " ".join(counts_str)
print(s)


import sys
sys.setrecursionlimit(10 ** 9)
N, Q = map(int, input().split())

G = [[] for i in range(N)]

for _ in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[b].append(a)
    G[a].append(b)

ans = [0] * N

for _ in range(Q):
    p, x = map(int, input().split())
    p -= 1
    ans[p] += x

def dfs(v, p):
    for to in G[v]:
        if to == p: continue
        ans[to] += ans[v]
        dfs(to, v)

dfs(0, -1)
for i in range(N):
    print(ans[i],end=' ')


import sys
sys.setrecursionlimit(10**6)
def dfs(tree, n, ans):
    for i in tree[n]:
        ans[i] += ans[n]
        tree[i].remove(n)
        dfs(tree, i, ans)

n, q = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n-1)]
px = [list(map(int,input().split())) for _ in range(q)]

g = [[] for _ in range(n)]
for i in range(n-1):
    g[ab[i][0]-1].append(ab[i][1]-1)
    g[ab[i][1]-1].append(ab[i][0]-1)

ans = [0]*n
for i in range(q):
    ans[px[i-1][0]-1] += px[i-1][1]
dfs(g, 0, ans)

print(*ans)

import sys
read = sys.stdin.read
sys.setrecursionlimit(10**7)
#readlines = sys.stdin.readlines
def main():
    def dfs(v, s):
        if added[v]:
            pass
        else:
            scores[v] += s
            added[v] = 1
            for nextv in gg[v]:
                dfs(nextv, scores[v])

    data = tuple(map(int, read().split()))
    n, q = data[0], data[1]
    gg = {i: set() for i in range(1, n + 1)}
    for i1, v1 in zip(data[2:n*2:2], data[3:n*2:2]):
        gg[v1].add(i1)
        gg[i1].add(v1)
    scores = [0] * (n + 1)
    for j1, v1 in zip(data[n*2::2], data[n*2+1::2]):
        scores[j1] += v1

    added = [0] * (n + 1)
    dfs(1, 0)
    print(*scores[1:], sep=' ')

def __starting_point():
    main()
__starting_point()

n,q = map(int,input().split())
graph = [[] for i in range(n)]
for i in range(n-1):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  graph[a].append(b)
  graph[b].append(a)

weight = [0 for i in range(n)]
for i in range(q):
  p,x = map(int,input().split())
  weight[p-1] += x

st = [0]
visit = [False for i in range(n)]
while not len(st) == 0:
  now = st.pop()
  visit[now] = True
  for e in graph[now]:
    if visit[e]:
      continue
    weight[e] += weight[now]
    st.append(e)
    
print(' '.join(map(str,weight)))


import sys
sys.setrecursionlimit(10 ** 6)
def main2():
    n, q = list(map(int, input().split()))
    tree = [[] for i in range(n)]
    point = [0] * n

    for _ in range(n - 1):
        a, b = list(map(int, input().split()))
        tree[b - 1].append(a - 1)
        tree[a - 1].append(b - 1)
    for i in range(q):
        p, x = list(map(int, input().split()))
        point[p - 1] += x

    def dfs(v, parent):
        nonlocal point, tree
        for next_val in tree[v]:
            if next_val == parent:
                continue
            point[next_val] += point[v]
            dfs(next_val, v)
    dfs(0, 0)
    print((*point))


def __starting_point():
    main2()

__starting_point()

# abc138 D ki

import sys
sys.setrecursionlimit(10**6)

# def input():
#     return sys.stdin.readline()[:-1]

N,Q = map(int,input().split())
g=[[] for _ in range(N)]

point=[0]*N

for _ in range(N-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    g[a].append(b)
    g[b].append(a)
    
for _ in range(Q):
    a,b=map(int,input().split())
    a-=1
    point[a]+=b

def dfs(n,pre=-1):
    for ne in g[n]:
        if ne == pre:
            continue
        
        point[ne]+=point[n]
        
        dfs(ne,n)
        
dfs(0)
print(*point)

import sys
sys.setrecursionlimit(10 ** 6)
def input():
    return sys.stdin.readline()[:-1]

def dfs(v,prev = -1):
    for u in graph[v]:
        if u == prev:
            continue
        point[u] += point[v]
        dfs(u,v)

N, Q = list(map(int,input().split()))
graph = [[] for _ in range(N)]
point = [0]*N

for i in range(N-1):
    a,b = list(map(int,input().split()))
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

for i in range(Q):
    p,x = list(map(int,input().split()))
    p -= 1
    point[p] += x

dfs(0)
print((*point))


from collections import defaultdict
N,Q = list(map(int,input().split()))
d = defaultdict(list)

for _ in range(N-1):
    a,b = list(map(int,input().split()))
    d[a].append(b)
    d[b].append(a)

c = defaultdict(int)

for _ in range(Q):
    p,x = list(map(int,input().split()))
    c[p] += x

ans = [0 for i in range(N)]
que = [(1,0,-1)]
while len(que)>0:
    tmp = []
    for v,x,par in que:
        x += c[v]
        ans[v-1] = str(x)
        for w in d[v]:
            if w != par:
                tmp.append((w,x,v))
    que = tmp

print((' '.join(ans)))


import sys
sys.setrecursionlimit(500000)

n, q = list(map(int, input().split()))
ab = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = list(map(int, input().split()))
    ab[a-1].append(b-1)
    ab[b-1].append(a-1)
add = [0]*n
for _ in range(q):
    pp, xx = list(map(int, input().split()))
    add[pp-1] += xx


def dfs(v, p, value):
    value += add[v]
    ans[v] = value
    for c in ab[v]:
        if c == p:
            continue
        dfs(c, v, value)


ans = [0]*n
dfs(0, -1, 0)
print((*ans))


import sys
sys.setrecursionlimit(10**6)# 各頂点ごとに所属する木の大きさを計算する
N,Q = list(map(int,input().split()))

E = [[] for _ in range(N+1)]
visited = [False for _ in range(N+1)]
Node_len = [1 for _ in range(N+1)]

for i in range(N-1):
    a,b = list(map(int,input().split()))
    E[a].append(b)
    E[b].append(a)

AS = [0 for i in range(N+1)]
def dfs(node,parent=-1):
    for child in E[node]:
        if child == parent:
            continue
        AS[child] += AS[node]
        dfs(child,node)

for q in range(Q):
    p,x = list(map(int,input().split()))
    AS[p] += x

dfs(1)
print((*AS[1:]))




import sys
from collections import deque
sys.setrecursionlimit(10 ** 6)
def input():
    return sys.stdin.readline()[:-1]

def dfs(s):
    stack = [s]
    visited = [False]*N
    while stack:
        v = stack.pop()
        if visited[v]:
            continue
        visited[v] = True
        for u in graph[v]:
            if not visited[u]:
                point[u] += point[v]
                stack.append(u)

N, Q = list(map(int,input().split()))
graph = [deque([]) for _ in range(N)]
point = [0]*N

for i in range(N-1):
    a,b = list(map(int,input().split()))
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

for i in range(Q):
    p,x = list(map(int,input().split()))
    p -= 1
    point[p] += x

dfs(0)
print((*point))


from collections import defaultdict

N, Q = list(map(int, input().split()))
d = defaultdict(list)

for _ in range(N - 1):
    a, b = list(map(int, input().split()))
    d[a].append(b)
    d[b].append(a)

c = defaultdict(int)

for _ in range(Q):
    p, x = list(map(int, input().split()))
    c[p] += x

ans = [0 for i in range(N)]
que = [(1, 0, -1)]
while len(que) > 0:
    tmp = []
    for v, x, par in que:
        x += c[v]
        ans[v - 1] = str(x)
        for w in d[v]:
            if w != par:
                tmp.append((w, x, v))
    que = tmp

print((*ans))


n,q=map(int,input().split())
e=[[] for i in range(n)]
for i in range(n-1):
  a,b=map(lambda x:int(x)-1,input().split())
  e[a].append(b)
  e[b].append(a)
ps=[0 for i in range(n)]
for i in range(q):
  p,x=map(int,input().split())
  ps[p-1]+=x

s=[-1 for i in range(n)]
sc=[0]
s[0]=0
while sc:
  nsc=[]
  for i in sc:
    s[i]+=ps[i]
    for j in e[i]:
      if s[j]==-1:
        nsc.append(j)
        s[j]=s[i]
  sc=nsc

r=""
for i in range(n):
  r+=str(s[i])+" "
print(r[:-1])

import sys
sys.setrecursionlimit(10 ** 6)
def input():
    return sys.stdin.readline()[:-1]

def dfs(v,prev = -1):
    for u in graph[v]:
        if u == prev:
            continue
        point[u] += point[v]
        dfs(u,v)

N, Q = list(map(int,input().split()))
graph = [[] for _ in range(N)]
point = [0]*N

for i in range(N-1):
    a,b = list(map(int,input().split()))
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

for i in range(Q):
    p,x = list(map(int,input().split()))
    p -= 1
    point[p] += x

dfs(0)
print((*point))


from collections import deque


def nearlist(N, LIST):
    NEAR = [set() for _ in range(N)]
    for a, b in LIST:
        NEAR[a - 1].add(b - 1)
        NEAR[b - 1].add(a - 1)
    return NEAR


def bfs(NEAR):
    que, frag = deque([0]), set([0])
    while que:
        q = que.popleft()
        for i in NEAR[q]:
            if i in frag:
                continue
            ans[i] += ans[q]
            que.append(i), frag.add(i)
    return

n, q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n - 1)]
px = [list(map(int, input().split())) for _ in range(q)]

ans = [0] * n
for p, x in px:
    ans[p - 1] += x

near = nearlist(n, ab)
bfs(near)
print(*ans)

#!/usr/bin/env python3
import sys

sys.setrecursionlimit(10 ** 8)
input = sys.stdin.readline


def dfs(now):
    seen[now] = True
    for next in branch[now]:
        if seen[next] is False:
            score[next] += score[now]
            dfs(next)


N, Q = list(map(int, input().split()))
branch = [set() for _ in range(N)]
for _ in range(N - 1):
    a, b = list(map(int, input().split()))
    branch[a - 1].add(b - 1)
    branch[b - 1].add(a - 1)
score = [0] * N
for _ in range(Q):
    p, x = list(map(int, input().split()))
    score[p - 1] += x

seen = [False] * N
for i in range(N):
    if seen[i] is False:
        dfs(i)

print((*score))


from collections import deque
n,q = map(int,input().split())
z = [[] for i in range(n+1)]
for i in range(n-1):
    a,b = map(int,input().split())
    z[a].append(b)
    z[b].append(a)
l = [list(map(int,input().split())) for i in range(q)]
p,x = [list(i) for i in zip(*l)]
c = [0] * n
for i in range(q):
    c[p[i]-1] += x[i]
queue = deque([1])
check = [1] * (n+1)
while queue:
    p = queue.popleft()
    if check[p]:
        for i in z[p]:
            if check[i]:
                c[i-1] += c[p-1]
                queue.append(i)
    check[p] = 0
print(' '.join(map(str,c)))

#
# abc138 d
#
import sys
from io import StringIO
import unittest
from collections import deque


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """4 3
1 2
2 3
2 4
2 10
1 100
3 1"""
        output = """100 110 111 110"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """6 2
1 2
1 3
2 4
3 6
2 5
1 10
1 10"""
        output = """20 20 20 20 20 20"""
        self.assertIO(input, output)


def resolve():
    N, Q = list(map(int, input().split()))
    AB = [list(map(int, input().split())) for _ in range(N-1)]
    PX = [list(map(int, input().split())) for _ in range(Q)]

    G = [[i+1, 0] for i in range(N)]
    for ab in AB:
        a, b = ab
        G[a-1][1] += 1
        G[b-1][1] += 1
        G[a-1].append(b)
        G[b-1].append(a)

    ans = [0] * N
    for px in PX:
        p, x = px
        ans[p-1] += x

    S = deque()

    F = [False] * N
    S.append(1)
    F[0] = True

    while S:
        p = S.pop()
        if G[p-1][1] == 0:
            continue

        for np in G[p-1][2:]:
            if F[np-1]:
                continue
            S.append(np)
            F[np-1] = True
            ans[np-1] += ans[p-1]

    print((*ans))


def __starting_point():
    # unittest.main()
    resolve()

__starting_point()

import sys
sys.setrecursionlimit(10 ** 9)
N, Q = map(int, input().split())

AB_TREE = [[] for i in range(N)]

for _ in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    AB_TREE[b].append(a)
    AB_TREE[a].append(b)

ans = [0] * (N + 1)

for _ in range(Q):
    p, x = map(int, input().split())
    p -= 1
    ans[p] += x


def dfs(v, p):
    for to in AB_TREE[v]:
        if to == p: continue
        ans[to] += ans[v]
        dfs(to, v)


dfs(0, -1)
for i in range(N):
    print(ans[i],end=' ')


import collections
N,Q = map(int,input().split())
lski = [[] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split())
    lski[a].append(b)
    lski[b].append(a)
countercost = collections.Counter()
for i in range(Q):
    p,x = map(int,input().split())
    countercost[p] += x

dist = [-1] * (N+1)
parent = [-1] * (N+1)
dist[0] = 0
dist[1] = countercost[1]

d = collections.deque()
d.append(1)

while d:
    v = d.popleft()
    for i in lski[v]:
        if parent[a] == b:
            continue
        if dist[i] != -1:
            continue
        parent[b] = a
        dist[i] = dist[v] + countercost[i]
        d.append(i)
dist.pop(0)
ansls = [str(i) for i in dist]
print(' '.join(ansls))

N,Q = map(int,input().split())
G = [[] for n in range(N)]
ans = N*[0]

for n in range(N-1):
  a,b = map(int,input().split())
  G[a-1].append(b-1)
  G[b-1].append(a-1)

for q in range(Q):
  p,x = map(int,input().split())
  ans[p-1]+=x

f = N*[1]
t = [0]
while t:
  v = t.pop()
  f[v] = 0
  for k in G[v]:
    if f[k]:
      ans[k]+=ans[v]
      t.append(k)

print(*ans)

import sys
from collections import deque
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N,Q = MI()
Graph = [[] for _ in range(N+1)]
for _ in range(N-1):
    a,b = MI()
    Graph[a].append(b)
    Graph[b].append(a)

count = [0]*(N+1)
add_count = [0]*(N+1)
for i in range(Q):
    p,x = MI()
    add_count[p] += x

flag = [-1]*(N+1)
count[1] = add_count[1]
deq = deque([(1,add_count[1])])
flag[1] = 0

while deq:
    n,r = deq.pop()
    for d in Graph[n]:
        if flag[d] == -1:
            flag[d] = 0
            count[d] = r+add_count[d]
            deq.appendleft((d,count[d]))

print((*count[1:]))


# D - Ki TLE
import sys
sys.setrecursionlimit(10**7)
N,Q = map(int,input().split())

# 有向グラフ
G = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    a -= 1; b -= 1
    G[a].append(b)
    G[b].append(a)
    
lst = []
for _ in range(Q):
    P,X = map(int,input().split())
    P-=1
    lst.append((P,X))

cnt = [0]*N
for p,x in lst:
    cnt[p] += x 
    
seen = [False]*N
def dfs(v):
    seen[v] = True# v を訪問済みにする
    # v から行ける各頂点 next_v について
    for next_v in G[v]:
        # next_v が探索済みならスルー
        if seen[next_v] == True:
             continue
        cnt[next_v] += cnt[v] 
        dfs(next_v)
dfs(0)
print(*cnt)

import sys
sys.setrecursionlimit(10 ** 6)

def dfs(v,prev = -1):
    for u in graph[v]:
        if u == prev:
            continue
        point[u] += point[v]
        dfs(u,v)

N, Q = list(map(int,input().split()))
graph = [[] for _ in range(N)]
point = [0]*N

for i in range(N-1):
    a,b = list(map(int,input().split()))
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

for i in range(Q):
    p,x = list(map(int,input().split()))
    p -= 1
    point[p] += x

dfs(0)
print((*point))


import sys
from typing import List, Tuple
import collections

Graph = List[List[int]]


def main():
    def input(): return sys.stdin.readline()[:-1]
    N, Q = list(map(int, input().split()))

    graph = [[] for _ in range(N+1)]
    for _ in range(1, N):
        a, b = list(map(int, input().split()))
        graph[a].append(b)
        graph[b].append(a)

    px = [0] * (N + 1)
    for _ in range(Q):
        p, x = list(map(int, input().split()))
        px[p] += x

    queue = collections.deque()
    queue.append(1)
    checked = [0] * (N + 1)
    while queue:
        v = queue.pop()
        checked[v] = 1
        for next_v in graph[v]:
            if checked[next_v] == 1: continue
            px[next_v] += px[v]
            queue.append(next_v)
    print((*px[1:]))

def __starting_point():
    main()


__starting_point()

import sys
sys.setrecursionlimit(10**7)

n,q=map(int,input().split())
ans=[0 for _ in range(n)]
gra=[[] for _ in range(n)]
visited=[0 for _ in range(n)]

for _ in range(n-1):
  a,b=map(int,input().split())
  gra[a-1].append(b-1)
  gra[b-1].append(a-1)
  
for _ in range(q):
  p,x=map(int,input().split())
  ans[p-1]+=x
  
def dfs(st):
  temp=gra[st]
  for i in temp:
    if visited[i]==0:
      visited[i]+=1
      ans[i]+=ans[st]
      dfs(i)
      
visited[0]+=1
dfs(0)

for h in range(n):
  ans[h]=str(ans[h])
  
print(' '.join(ans))

import collections

n,q = map(int, input().split())

value = ['-'] * (n+1)

connected = [set() for i in range(n+1)]

for i in range(n-1):
  a,b = map(int, input().split())
  connected[a].add(b)
  connected[b].add(a)

for i in range(q):
  p,x = map(int, input().split())
  if value[p] == '-':
    value[p] = 0
  value[p] -= x

queue = collections.deque(connected[1])

if value[1] == '-':
  value[1] = 0
else:
  value[1] = -value[1]

for i in queue:
  if value[i] == '-':
    value[i] = 0
  else:
    value[i] = -value[i]
  value[i] += value[1]


while queue:
  s = queue.popleft()
  v = value[s]
  for i in connected[s]:
    vi = value[i]
    if vi == '-' or vi < 0:
      if vi == '-':
        vi = 0
      value[i] = -(vi-v)
      queue.append(i)
    
print(' '.join(str(i) for i in value[1:]))

import sys
sys.setrecursionlimit(10**9)
def f(p,q=-1):
  for i in c[p]:
    if i!=q:
      A[i]+=A[p]
      f(i,p)
n,q=map(int,input().split())
c=[[]for _ in range(n)]
for i in range(n-1):
  a,b=map(int,input().split())
  c[a-1].append(b-1)
  c[b-1].append(a-1)
A=[0]*n
for _ in range(q):
  p,x=map(int,input().split())
  A[p-1]+=x
f(0)
print(*A)

from collections import deque
n, q = list(map(int, input().split()))
graphs = [set() for _ in range(n)]
for _ in range(n - 1):
    a, b = [int(x) - 1 for x in input().split()]
    graphs[a].add(b)
    graphs[b].add(a)

nodes = [0 for _ in range(n)]
for _ in range(q):
    p, x = list(map(int, input().split()))
    nodes[p - 1] += x

done = [True for _ in range(n)]
D = deque()
D.append([0, 0])
ans = [0 for _ in range(n)]
while D:
    node, value = D.popleft()
    value += nodes[node]
    ans[node] = value
    done[node] = False
    for g in graphs[node]:
        if done[g]:
            D.append([g, value])

print((*ans))


import sys
sys.setrecursionlimit(10**9)

N, Q = map(int, input().split())
T = [[] for _ in range(N)]

for _ in range(N-1):
    a, b = map(int, input().split())
    T[a-1].append(b-1)
    T[b-1].append(a-1)

S = [0] * N

for _ in range(Q):
    p, x = map(int, input().split())
    S[p-1] += x

def search(p, q=-1):
    for a in T[p]:
        if a != q:
            S[a] += S[p]
            search(a, p)

search(0)
print(*S)

def solve():
    import sys
    sys.setrecursionlimit(10**6)
    def dfs(tree, n, ans):
        for i in tree[n]:
            ans[i] += ans[n]
            tree[i].remove(n)
            dfs(tree, i, ans) #再帰関数になっている。次の木の中を探索
     
    n, q = map(int,input().split())
    ab = [list(map(int,input().split())) for _ in range(n-1)]
    px = [list(map(int,input().split())) for _ in range(q)]
     
    g = [[] for _ in range(n)]
    for i in range(n-1):
        g[ab[i][0]-1].append(ab[i][1]-1)
        g[ab[i][1]-1].append(ab[i][0]-1)
    
    ans = [0]*n
    for i in range(q):
        ans[px[i-1][0]-1] += px[i-1][1]
    dfs(g, 0, ans)
     
    print(*ans)
    
def __starting_point():
    solve()
__starting_point()

import sys
from functools import lru_cache
sys.setrecursionlimit(10**7)
 
N,Q=map(int,input().split())
T=[[] for _ in range(N+1)]
for _ in range(N-1):
  a,b=map(int,input().split())
  T[a].append(b)
  T[b].append(a)

S=[0]*(N+1)
for _ in range(Q):
  p,x=map(int,input().split())
  S[p]+=x

@lru_cache(maxsize=None)
def dfs(now,prev=-1):
  for next in T[now]:
    if next==prev:
      continue
    S[next]+=S[now]
    dfs(next,now)

dfs(1)
print(*S[1:])

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
 
# 遅延評価で加えてあげるだけ
 
N,Q = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(N-1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
 
graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)
 
value = [0] * (N+1)
for p,x in PX:
    value[p] += x
 
def dfs(v,parent,add):
    value[v] += add
    for x in graph[v]:
        if x == parent:
            continue
        dfs(x,v,value[v])
 
dfs(1,0,0)
 
answer = ' '.join(map(str,value[1:]))
print(answer)

import collections

n, q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n-1)]
px = [list(map(int, input().split())) for _ in range(q)]

c = [[] for _ in range(n)]
for a, b in ab:
    a, b = a-1, b-1
    c[a].append(b)
    c[b].append(a)

point = [0] * n
for p, x in px:
    point[p-1] += x

parents = [0] * n
ans = [0] * n
q = collections.deque()
q.append(0)
while q:
    v = q.pop()
    ans[v] = ans[parents[v]] + point[v]
    for i in c[v]:
        if i == parents[v]:
            continue
        parents[i] = v
        q.append(i)
print(' '.join(list(map(str, ans))))

from collections import deque
n,q=map(int,input().split())
tree=[[] for _ in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    tree[a].append(b)
    tree[b].append(a)
count=[0]*n
for _ in range(q):
    p,cnt=map(int,input().split())
    count[p-1]+=cnt
stack=deque([[0,0,-1]])
while stack:
    num,cnt,pr=stack.pop()
    count[num]+=cnt
    for k in tree[num]:
        if k==pr:
            continue
        stack.append([k,count[num],num])
print(*count)

import sys
from collections import defaultdict
sys.setrecursionlimit(1000000)
N, Q = map(int,input().split())
edges = [[] for _ in range(N)]
for _ in range(N-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    edges[a].append(b)
    edges[b].append(a)

d = defaultdict(int)
for _ in range(Q):
    p,x = map(int,input().split())
    d[p-1] += x
visited = [False]*N
cnt = [0]*N
def dfs(n, acc):
    cnt[n] = acc
    for m in edges[n]:
        if not visited[m]:
            visited[m] = True
            dfs(m, acc+d[m])
visited[0] = True
dfs(0, d[0])
print(*cnt)

from collections import deque
import numpy as np

N, Q = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N-1)]
P = [list(map(int, input().split())) for _ in range(Q)]

link = [[] for _ in range(N)]
for i in range(N-1):
    link[A[i][0]-1].append(A[i][1]-1)
    link[A[i][1]-1].append(A[i][0]-1)


ans = [0 for _ in range(N)]
for i in range(Q):
  ans[P[i][0] - 1] += P[i][1]

dist = [-1 for _ in range(N)]
dist[0] = 0
d = deque([0])
while d:
    now = d.pop()
    for i in range(len(link[now])):
        if dist[link[now][i]] == -1:
            ans[link[now][i]] += ans[now]
            dist[link[now][i]] = 0
            d.append(link[now][i])

for i in range(N):
    if i != N - 1:
        print(ans[i], end=" ")
    else:
        print(ans[i])


import sys
read = sys.stdin.read
sys.setrecursionlimit(10**7)
#readlines = sys.stdin.readlines
def main():
    def dfs(v, s):
        if notseen[v]:
            scores[v] += s
            notseen[v] = 0
            for nextv in gg[v]:
                dfs(nextv, scores[v])

    data = tuple(map(int, read().split()))
    n, q = data[0], data[1]
    gg = {i: set() for i in range(1, n + 1)}
    # 木なので”正しく”処理すればgg[x]へのaddは２回ではなく１回でいいはず。
    # だがうまく行かないため、無向グラフのように２回加えて、dfs関数で各頂点を１回しかみないように対応。
    for i1, v1 in zip(data[2:n*2:2], data[3:n*2:2]):
        gg[v1].add(i1)
        gg[i1].add(v1)
    scores = [0] * (n + 1)
    for j1, v1 in zip(data[n*2::2], data[n*2+1::2]):
        scores[j1] += v1

    notseen = [1] * (n + 1)
    dfs(1, 0)
    print(*scores[1:], sep=' ')

def __starting_point():
    main()
__starting_point()

from collections import deque
N,Q = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(N-1)]
px = [list(map(int,input().split())) for _ in range(Q)]

tree = [[] for _ in range(N)]
for a, b in ab:
  tree[a-1].append(b-1)
  tree[b-1].append(a-1)

counter = [0] * N
for p, x in px:
  counter[p-1] += x
  
flag = [1] * N
t = deque()
t.append(0)

#1(0)から順に探索していけば、自然と親→子の順番になる
while t:
  v = t.popleft()
  flag[v] = 0
  for i in tree[v]:
    if flag[i]:
      counter[i] += counter[v]
      t.append(i)
      
print(*counter)

from collections import defaultdict
from sys import setrecursionlimit
setrecursionlimit(10 ** 7)

n,q = map(int,input().split())

node = [[] for _ in range(n+1)]
counter = [0 for _ in range(n+1)]
visited = [0 for _ in range(n+1)]
point_dic = defaultdict(int)

for _ in range(n-1):
    a,b = map(int,input().split())
    node[a].append(b)
    node[b].append(a)

for _ in range(q):
    p,x = map(int,input().split())
    point_dic[p] += x

def dfs(now,before):
    nonlocal counter
    nonlocal visited

    if visited[now]:
        return
    
    if point_dic[now]:
        point = point_dic[now]+before
    else:
        point = before
    
    visited[now] = 1
    counter[now] += point

    for i in node[now]:
        if visited[i]:
            continue

        dfs(i,point)

dfs(1,0)

print(' '.join(map(str, counter[1:])))

from collections import deque


N, Q = list(map(int, input().split()))
t = [[] for i in range(N + 1)]

for i in range(N - 1):
    a, b = list(map(int, input().split()))
    t[a].append(b)
    t[b].append(a)

score = [0] * (N + 1)
for i in range(Q):
    p, x = list(map(int, input().split()))
    score[p] += x

is_read = [False] * (N + 1)
d = deque()
d.append(1)

while len(d) != 0:
    now = d.popleft()
    is_read[now] = True
    for c in t[now]:
        if is_read[c]:
            continue
        score[c] += score[now]
        d.append(c)
print((" ".join(map(str, score[1:]))))


import sys
sys.setrecursionlimit(10**6)
def dfs(tree, n, ans):
    for i in tree[n]:
        ans[i] += ans[n]
        tree[i].remove(n)
        dfs(tree, i, ans)
 
n, q = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n-1)]
px = [list(map(int,input().split())) for _ in range(q)]
 
g = [[] for _ in range(n)]
for i in range(n-1):
    g[ab[i][0]-1].append(ab[i][1]-1)
    g[ab[i][1]-1].append(ab[i][0]-1)
 
ans = [0]*n
for i in range(q):
    ans[px[i-1][0]-1] += px[i-1][1]
dfs(g, 0, ans)
 
print(*ans)

# import itertools
# import math
import sys
sys.setrecursionlimit(500*500)
# import numpy as np
# from collections import deque
# import heapq

# N = int(input())
# S = input()
# n, *a = map(int, open(0))
N, Q = map(int, input().split())
# A = list(map(int, input().split()))
# A = list(map(lambda x: int(x)*(-1), input().split()))
# B = list(map(int, input().split()))
# A_B = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

edges = [list(map(int,input().split())) for _ in range(N - 1)]
tree = [[] for _ in range(N + 1)]

for edge in edges:
    tree[edge[0]].append(edge[1])
    tree[edge[1]].append(edge[0])

depth = [-1] * (N + 1)
depth[1] = 0
count = [0] * (N + 1)

for i in range(Q):
    p, x = map(int, input().split())
    count[p] += x

# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + 1
#             dfs(tree, l[0])
# dfs(tree, 1)
def dfs(tree, s):
    for l in tree[s]:
        if depth[l] == -1:
            depth[l] = 0
            count[l] += count[s]
            dfs(tree, l)
dfs(tree, 1)


for i in count[1:]:
    print(i, end = ' ')

# def factorization(n):
#     arr = []
#     temp = n
#     for i in range(2, int(-(-n**0.5//1))+1):
#         if temp%i==0:
#             cnt=0
#             while temp%i==0:
#                 cnt+=1
#                 temp //= i
#             arr.append([i, cnt])
#     if temp!=1:
#         arr.append([temp, 1])
#     if arr==[]:
#         arr.append([n, 1])
#     return arr



# bfs
# tree = [[] for _ in range(N + 1)]
# edges = [list(map(int,input().split())) for _ in range(M)]

# for edge in edges:
#     tree[edge[0]].append(edge[1])
#     tree[edge[1]].append(edge[0])

# depth = [-1] * (N + 1)
# depth[1] = 0

# d = deque()
# d.append(1)

# ans = [0] * (N + 1)
# while d:
#  v = d.popleft()
#  for i in tree[v]:
#    if depth[i] != -1:
#      continue
#    depth[i] = depth[v] + 1
#    ans[i] = v
#    d.append(i)

# # ans = depth[2:]
# print('Yes')
# print(*ans[2:], sep="\n")

import sys
from functools import lru_cache
sys.setrecursionlimit(10**7)

N, Q = map(int, input().split())
T = [[] for _ in range(N+1)]
for _ in range(N-1):
  a,b=map(int, input().split())
  T[a].append(b)
  T[b].append(a)

V = [0] * (N+1)
for q in range(Q):
  p,x=map(int, input().split())
  V[p]+=x

@lru_cache(maxsize=None)
def dfs(i, parent, acc):
  V[i]+=acc
  for j in T[i]:
    if j != parent:
      dfs(j,i,V[i])

cur,parent,acc=1,0,0
dfs(cur,parent,acc)
print(*V[1:])

import collections,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,Q = LI()
ab = [LI() for _ in range(N-1)]
px = [LI() for _ in range(Q)]
ans = [0]*(N+1) #1_indexed
graph = {i:collections.deque() for i in range(1,N+1)} #1_indexed
for a,b in ab:
        graph[a].append(b)
        graph[b].append(a)
for p,x in px:
    ans[p] += x
seen = [0]*(N+1) #1_indexed
stack = []
def dfs():
    seen[1] = 1
    stack.append(1)
    while stack:
        s = stack.pop()
        if not graph[s]:
            continue
        for j in range(len(graph[s])):
            g_NO = graph[s].popleft()
            if seen[g_NO]:
                continue
            seen[g_NO] = 1
            stack.append(g_NO)
            ans[g_NO] += ans[s]
dfs()
print(*ans[1:])

import sys
sys.setrecursionlimit(10**9)

N, Q = map(int,input().split())
G = [[] for _ in range(N)]
counter = [0] * N

for _ in range(N-1):
    a, b = map(int,input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

for _ in range(Q):
    p, x = map(int,input().split())
    counter[p-1] += x

seen = [False]*N

def dfs(v, seen, G, counter):
    seen[v] = True
    for u in G[v]:
        if not seen[u]:
            counter[u] += counter[v]
            dfs(u, seen, G, counter)

dfs(0, seen, G, counter)

for c in counter:
    print(c, end = " ")
print("")



import sys
from collections import deque
sys.setrecursionlimit(10 ** 6)
def input():
    return sys.stdin.readline()[:-1]

def dfs(s):
    stack = [s]
    visited = [False]*N
    while stack:
        v = stack.pop()
        if visited[v]:
            continue
        visited[v] = True
        for u in graph[v]:
            if not visited[u]:
                point[u] += point[v]
                stack.append(u)

N, Q = list(map(int,input().split()))
graph = [deque([]) for _ in range(N)]
point = [0]*N

for i in range(N-1):
    a,b = list(map(int,input().split()))
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

for i in range(Q):
    p,x = list(map(int,input().split()))
    p -= 1
    point[p] += x

dfs(0)
print((*point))


#!/usr/bin/env python3
from sys import setrecursionlimit

setrecursionlimit(10 ** 8)


def dfs(now):
    seen[now] = True
    score[now] += operation[now]
    for next in branch[now]:
        if seen[next] is False:
            score[next] += score[now]
            dfs(next)


N, Q = map(int, input().split())
branch = [set() for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    branch[a - 1].add(b - 1)
    branch[b - 1].add(a - 1)
operation = [0] * N
for _ in range(Q):
    p, x = map(int, input().split())
    operation[p - 1] += x

seen = [False] * N
score = [0] * N
for i in range(N):
    if seen[i] is False:
        dfs(i)

for ans in score:
    print(ans, end=' ')


import sys
readline = sys.stdin.readline

N,Q = map(int,readline().split())

G = [[] for i in range(N)]

for i in range(N - 1):
  a,b = map(int,readline().split())
  G[a - 1].append(b - 1)
  G[b - 1].append(a - 1)
  
point = [0] * N
for i in range(Q):
  p,x = map(int,readline().split())
  point[p - 1] += x

stack = [(0, -1, 0)]
while stack:
  v,parent,p = stack.pop()
  point[v] += p
  p = point[v]
  for child in G[v]:
    if child == parent:
      continue
    stack.append([child, v, p])
  
print(*point)

def main():
	N, Q = [int(n) for n in input().split(" ")]
	edges = [[] for i in range(N)]
	counter = [0] * N

	for i in range(N - 1):
		a, b = [int(x) for x in input().split(" ")]
		edges[a - 1].append(b - 1)
		edges[b - 1].append(a - 1)

	for j in range(Q):
		p, x = [int(q) for q in input().split(" ")]
		counter[p - 1] += x

	to_visit = [0]
	checked = [1] + [0] * (N - 1)
	tree = [0] * N

	while len(to_visit) > 0:
		visiting = to_visit.pop()
		tree[visiting] += counter[visiting]
		for e in edges[visiting]:
			if checked[e] == 0:
				checked[e] = 1
				to_visit.append(e)
				tree[e] = tree[visiting]

	print((" ".join([str(s) for s in tree])))

main()


import sys
sys.setrecursionlimit(10**8)

n, q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n-1)]
px = [list(map(int, input().split())) for _ in range(q)]

t = dict()
for i in range(1, n+1):
    t[i] = set()
for a, b in ab:
    t[a].add(b)
    t[b].add(a)

cnt = [0] * n
s = set()
for p, x in px:
    cnt[p-1] += x

def solve(p):
    s.add(p)
    for c in t[p]:
        if c not in s:
            cnt[c-1] += cnt[p-1]
            solve(c)
solve(1)
print(*cnt, sep=' ')


from collections import deque

N, Q = list(map(int, input().split()))
tree = [set() for _ in range(N+1)]

for i in range(N - 1):
    n1, n2 = list(map(int, input().split()))
    tree[n1].add(n2)
    tree[n2].add(n1)

scores = [0]*(N+1)
for _ in range(Q):
    p, x = list(map(int, input().split()))
    scores[p] += x

q = deque()
q.append(1)
checked = [False]*(N+1)
while q:
    v = q.pop()
    checked[v] = True
    s = scores[v]
    for k in tree[v]:
        if checked[k]:
            continue
        scores[k] += s
        q.append(k)

print((*scores[1:]))


import sys
sys.setrecursionlimit(10**9)

N,Q=map(int,input().split())
T=[[] for _ in range(N)]
for _ in range(N-1):
  a,b=map(int,input().split())
  a-=1;b-=1
  T[a].append(b)
  T[b].append(a)

V=[0]*N
for _ in range(Q):
  p,x=map(int,input().split())
  p-=1
  V[p]+=x
  
def dfs(now,prev=-1):
  for next in T[now]:
    if next==prev:
      continue
    V[next]+=V[now]
    dfs(next,now)

dfs(0)
print(*V)

import sys
sys.setrecursionlimit(1<<30)
N,Q = map(int,input().split())
def dfs(x, score):
    for y in Tree[x]:
        if Parent[x] != y:
            Parent[y] = x
            score[y] += score[x]
            dfs(y, score)
Tree = [[] for i in range(N+1)]
Parent = [0]*(N+1)
for i in range(N-1):
    a,b = map(int,input().split())
    Tree[a].append(b)
    Tree[b].append(a)
score = [0]*(N+1)
for j in range(Q):
    p,x = map(int,input().split())
    score[p] += x
dfs(1,score)
print(*score[1:],end="\t")

import sys
sys.setrecursionlimit(10**9)

N, Q = map(int, input().split())
L = [[] for _ in range(N)]

for _ in range(N-1):
    a, b = map(int, input().split())
    L[a-1].append(b-1)
    L[b-1].append(a-1)

S = [0] * N

for _ in range(Q):
    p, x = map(int, input().split())
    S[p-1] += x

def search(p,q=-1):
    for a in L[p]:
        if a != q:
            S[a] += S[p]
            search(a,p)

search(0)
print(*S)

import sys
sys.setrecursionlimit(10**7)
N, Q = [int(n) for n in input().split()]
tree_list = [[] for _ in range(N)]

for i in range(N-1):
    a, b = [int(n)-1 for n in input().split()]
    tree_list[a].append(b)
    tree_list[b].append(a)

score_list = [0] * N
for j in range(Q):
    p, x = [int(n) for n in input().split()]
    score_list[p-1] += x

reached = [False] * N
def dfs(v):
    reached[v] = True
    for next_v in tree_list[v]:
        if reached[next_v] == True:
            continue
        score_list[next_v] += score_list[v]
        dfs(next_v)
dfs(0)
print(*score_list)

from collections import deque

N, Q = list(map(int, input().split())) # Nは頂点の数、Qは操作の回数
graph = [[] for _ in range(N+1)]
for _ in range(N-1):
    a, b = list(map(int, input().split()))
    graph[a].append(b)
    graph[b].append(a)

counts = [0] * (N+1)
for _ in range(Q):
    p, x  = list(map(int, input().split()))
    counts[p] += x
visited = [-1] * (N+1)

q = deque()
q.append(1)
visited[1] = 1
while q:
    node = q.pop()

    next_nodes = graph[node]
    for next in next_nodes:
        if visited[next] != -1:
            continue
        q.append(next)
        visited[next] = 1
        counts[next] += counts[node]

print((*counts[1:]))




import sys
sys.setrecursionlimit(10000000)
def main():
    n,q = list(map(int,input().split()))
    Ki = [[] for i in range(n)]
    for _ in range(n-1):
        a,b = list(map(int,input().split()))
        Ki[a-1]+=[b-1]
        Ki[b-1]+=[a-1]
    ans = [0]*n
    for _ in range(q):
        p,x = list(map(int,input().split()))
        ans[p-1]+=x
    def add(N=0,L=-1):
        for k in Ki[N]:
            if k!=L:
                ans[k]+=ans[N]
                add(k,N)
    add()
    print((' '.join([str(a) for a in ans])))

def __starting_point():
    main()

__starting_point()

import sys
sys.setrecursionlimit(10**9)
n,q=map(int,input().split())
G=[[] for _ in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    G[a].append(b)
    G[b].append(a)

subtree_size=[0]*n
cnt=[0]*n

for _ in range(q):
    p,x=map(int,input().split())
    p-=1
    cnt[p]+=x
ans=[0]*n

def dfs(G,v,p):
    ans[v]+=cnt[v]
    for nv in G[v]:
        if nv==p:
            continue
        cnt[nv]+=cnt[v]
        dfs(G,nv,v)
    
    subtree_size[v]=1
    for c in G[v]:
        if c==p:
            continue
        subtree_size[v]+=subtree_size[c]

root=0
dfs(G,root,-1)

for i in range(n):
    print(ans[i],end=' ')





import sys
sys.setrecursionlimit(10**8)
N, Q = map(int, input().split())
g = [[] for i in range(N)]
for i in range(N-1):
    a, b = list(map(int, input().split()))
    g[a-1].append(b-1)
    g[b-1].append(a-1)
cnt = [0] * N
for i in range(Q):
    p, x = list(map(int, input().split()))
    cnt[p-1] += x

def dfs(g, v):
    # nonlocal ans_cnt
    for nv in g[v]:
        if ans_cnt[nv] != -1: continue
        ans_cnt[nv] = cnt[nv] + ans_cnt[v]
        dfs(g, nv)

ans_cnt = [-1] * N
ans_cnt[0] = cnt[0]
dfs(g, 0)

# print(cnt)
# print(ans_cnt)
for i, value in enumerate(ans_cnt):
    print(value, end="")
    if i != len(ans_cnt)-1:
        print(" ", end="")
print()

import sys
sys.setrecursionlimit(10**7)
n,q=map(int,input().split())
edge=[[] for _ in range(n)]
for i in range(n-1):
    x,y=map(int,input().split())
    edge[x-1].append(y-1)
    edge[y-1].append(x-1)
ans=[0]*n
for i in range(q):
    p,x=map(int,input().split())
    ans[p-1]+=x
def dfs(c,p):
    for i in edge[c]:
        if i==p:
            continue
        ans[i]+=ans[c]
        dfs(i,c)
dfs(0,-1)
print(*ans)

N,Q = map(int,input().split())
G = [[] for n in range(N)]
ans = N*[0]
 
for n in range(N-1):
  a,b = map(int,input().split())
  G[a-1].append(b-1)
  G[b-1].append(a-1)
 
for q in range(Q):
  p,x = map(int,input().split())
  ans[p-1]+=x
 
f = N*[1]
t = [0]
while t:
  v = t.pop()
  f[v] = 0
  for k in G[v]:
    if f[k]:
      ans[k]+=ans[v]
      t.append(k)
 
print(*ans)

import sys
sys.setrecursionlimit(10**8)

n, q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n-1)]
px = [list(map(int, input().split())) for _ in range(q)]

t = dict()
for i in range(1, n+1):
    t[i] = []
for a, b in ab:
    t[a].append(b)
    t[b].append(a)

cnt = [0] * n
s = set()
for p, x in px:
    cnt[p-1] += x

def solve(p):
    s.add(p)
    for c in t[p]:
        if c not in s:
            cnt[c-1] += cnt[p-1]
            solve(c)
solve(1)
print(*cnt, sep=' ')


import sys
# import math
# import bisect
# import numpy as np
# from decimal import Decimal
# from numba import njit, i8, u1, b1 #JIT compiler
# from itertools import combinations, product
from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_ints2(x):   return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def GCD(a: int, b: int) -> int: return b if a%b==0 else GCD(b, a%b)
def LCM(a: int, b: int) -> int: return (a * b) // GCD(a, b)

def Main():
    n, q = read_ints()
    tree = [[] for _ in range(n)]
    c = [0] * n
    for _ in range(n-1):
        a, b = read_ints()
        tree[~-a].append(~-b)
        tree[~-b].append(~-a)
    for _ in range(q):
        p, x = read_ints()
        c[~-p] += x
    que = deque([0])
    seen = [False] * n
    while que:
        p = que.pop()
        seen[p] = True
        for x in tree[p]:
            if seen[x]: continue
            que.append(x)
            c[x] += c[p]
    
    print(*c)

def __starting_point():
    Main()
__starting_point()

from collections import defaultdict
N,Q = list(map(int,input().split()))
d = defaultdict(list)

for _ in range(N-1):
    a,b = list(map(int,input().split()))
    d[a].append(b)
    d[b].append(a)

c = defaultdict(int)

for _ in range(Q):
    p,x = list(map(int,input().split()))
    c[p] += x

ans = [0 for i in range(N)]
que = [(1,0,-1)]
while len(que)>0:
    tmp = []
    for v,x,par in que:
        x += c[v]
        ans[v-1] = str(x)
        for w in d[v]:
            if w != par:
                tmp.append((w,x,v))
    que = tmp

print((*ans))


import sys
sys.setrecursionlimit(10**9)
n,q=map(int,input().split())
G=[[] for _ in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    G[a].append(b)
    G[b].append(a)

subtree_size=[0]*n
cnt=[0]*n

for _ in range(q):
    p,x=map(int,input().split())
    p-=1
    cnt[p]+=x
ans=[0]*n

def dfs(G,v,p):
    ans[v]+=cnt[v]
    for nv in G[v]:
        if nv==p:
            continue
        cnt[nv]+=cnt[v]
        dfs(G,nv,v)
    
    subtree_size[v]=1
    for c in G[v]:
        if c==p:
            continue
        subtree_size[v]+=subtree_size[c]

root=0
dfs(G,root,-1)

for i in range(n):
    print(ans[i],end=' ')





import sys
import math

#https://atcoder.jp/contests/agc008/submissions/15248942
sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

class Node:
    def __init__(self):
        self.edge = []
        self.count = 0

def dfs(tree,node,p_node,p_count,counts):
    count = tree[node].count + p_count
    counts[node] = count
    for x in tree[node].edge:
        if x == p_node:
            continue
        dfs(tree,x,node,count,counts)

N,Q = inm()

tree = []
for _ in range(N):
    tree.append(Node())

#node = Node()
#tree = [node]*N

for _ in range(N-1):
    a,b = inm()
    tree[a-1].edge.append(b-1)
    tree[b-1].edge.append(a-1)

for _ in range(Q):
    p,x = inm()
    tree[p-1].count += x

val = []
for _ in range(N):
    val.append(0)

#for i in range(N):
#    print(tree[i].edge)
#    print(tree[i].count)

dfs(tree,0,-1,0,val)

counts_str = [str(n) for n in val]
s = " ".join(counts_str)
print(s)


from collections import defaultdict
from sys import setrecursionlimit # 再帰エラー対策
setrecursionlimit(10 ** 7)

n,q = map(int,input().split())

node = [[] for _ in range(n+1)]
counter = [0 for _ in range(n+1)]
visited = [0 for _ in range(n+1)]
point_dic = defaultdict(int)

for _ in range(n-1):
    a,b = map(int,input().split())
    node[a].append(b)
    node[b].append(a)

# 各ノードの加算値を記録
for _ in range(q):
    p,x = map(int,input().split())
    point_dic[p] += x

# 現在のノード(now)とそれまでに加算された値(before_point)
def dfs(now,before_point):
    if visited[now]:
        return
    
    # 現在のノードの加算値を足す
    if point_dic[now]:
        point = point_dic[now]+before_point
    else:
        point = before_point
    
    # 訪問済みにする
    visited[now] = 1
    counter[now] += point

    for i in node[now]:
        if visited[i]:
            continue

        dfs(i,point) # 再帰して子ノードに引き継ぐ

dfs(1,0)

print(' '.join(map(str, counter[1:])))

import sys
sys.setrecursionlimit(10 ** 6)

def input():
    return sys.stdin.readline()[:-1]
N , Q = map(int,input().split())
graph = [[] for _ in range(N)]
point = [0] * N
for _ in range(N - 1):
    a , b = map(int,input().split())
    graph[a - 1].append(b - 1)
    graph[b - 1].append(a - 1)
#print(graph)
for _ in range(Q):
    a , b = map(int,input().split())
    a = a - 1
    point[a] += b
# dfsを用いて累積和を計算する
# 初期状態だと前の値がないためデフォルト引数に-1を代入
def dfs(now , prev = -1):
    for next in graph[now]:
        # 次のノードが前に参照した値の時はcontinue
        if next == prev:
            continue
        # 現在の値を次のポイントに加算することで累積和をとる
        point[next] += point[now]
        # 次のノードと現在のノードを引数にdfsを継続する
        dfs(next , now)

dfs(0)
print(*point)