Buggy python submission (verdict: Time Limit Exceeded):
# D - Ki
import sys
sys.setrecursionlimit(10**7)

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

# 各頂点に得点を持たせておく
point = [0] * N
for i in range(Q):
    p, x = map(int, input().split())
    p -= 1
    point[p] += x

ans = [0] * N
def dfs(now, par, pnt):
    ans[now] += pnt + point[now]
    for gi in g[now]:
        if gi!=par:
            dfs(gi, now, ans[now])

dfs(0, 0, 0)

print(' '.join(map(str, ans)))


Fixed submission:
# D - Ki

from collections import deque

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

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

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

done = [-1]*n
done[0] = 1
d = deque()
d.append((0, 0))

while len(d)>0:
    v = d.popleft()
    cnt[v[0]] += v[1]
    done[v[0]] = 1
    for i in graph[v[0]]:
        if done[i]<0:
            d.append((i, cnt[v[0]]))

print(' '.join(map(str, cnt)))

Buggy python submission (verdict: Time Limit Exceeded):
# D - Ki
import sys
sys.setrecursionlimit(10**7)

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

# 各頂点に得点を持たせておく
point = [0] * N
for i in range(Q):
    p, x = map(int, input().split())
    p -= 1
    point[p] += x

ans = [0] * N
def dfs(now, par, pnt):
    ans[now] += pnt + point[now]
    for gi in g[now]:
        if gi!=par:
            dfs(gi, now, ans[now])

dfs(0, 0, 0)

print(' '.join(map(str, ans)))

Fixed submission:
# D - Ki

from collections import deque

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

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

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

done = [-1]*n
done[0] = 1
d = deque()
d.append((0, 0))

while len(d)>0:
    v = d.popleft()
    cnt[v[0]] += v[1]
    done[v[0]] = 1
    for i in graph[v[0]]:
        if done[i]<0:
            d.append((i, cnt[v[0]]))

print(' '.join(map(str, cnt)))

Buggy python submission (verdict: Time Limit Exceeded):
# D - Ki
import sys
sys.setrecursionlimit(10**7)

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

def searchPar(now, par):
    parent[now] = par
    for gi in g[now]:
        if gi!=par:
            searchPar(gi, now)

def dfs(p, q):
    ans[p] += q
    for gi in g[p]:
        if parent[p]!=gi:
            dfs(gi, q)

# 各頂点の親を探す
parent = [0] * N
for i in range(N):
    searchPar(0, 0)

ans = [0] * N
for i in range(Q):
    p, x = map(int, input().split())
    p -= 1
    dfs(p, x)
print(' '.join(map(str, ans)))

Fixed submission:
# D - Ki

from collections import deque

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

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

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

done = [-1]*n
done[0] = 1
d = deque()
d.append((0, 0))

while len(d)>0:
    v = d.popleft()
    cnt[v[0]] += v[1]
    done[v[0]] = 1
    for i in graph[v[0]]:
        if done[i]<0:
            d.append((i, cnt[v[0]]))

print(' '.join(map(str, cnt)))