Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
from collections import defaultdict

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

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

q = deque()
ans = [0] * (N+1)
ans[1] = P[1]

for t in T[1]:
    q.append([1, t])
while q:
    a, b = q.popleft()
    ans[b] += ans[a] + P[b]
    for t in T[b]:
        q.append([b, t])

print(*ans[1:])


Fixed submission:
from collections import deque
from collections import defaultdict
import sys
readline = sys.stdin.readline

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

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

q = deque()
ans = [0] * (N+1)
ans[1] = P[1]

for t in T[1]:
    q.append([1, t])
while q:
    a, b = q.popleft()
    ans[b] += ans[a] + P[b]
    for c in T[b]:
        q.append([b, c])

print(*ans[1:])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
from collections import defaultdict

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

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

q = deque()
ans = [0] * (N+1)
ans[1] = P[1]

for t in T[1]:
    q.append([1, t])
while q:
    a, b = q.popleft()
    ans[b] += ans[a] + P[b]
    for t in T[b]:
        q.append([b, t])

print(*ans[1:])


Fixed submission:
from collections import deque
from collections import defaultdict
import sys
readline = sys.stdin.readline

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

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

q = deque()
ans = [0] * (N+1)
ans[1] = P[1]

for t in T[1]:
    q.append([1, t])
while q:
    a, b = q.popleft()
    ans[b] += ans[a] + P[b]
    for c in T[b]:
        q.append([b, c])

print(*ans[1:])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
from collections import defaultdict

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

q = deque()
ans = [0] * (N+1)

T = defaultdict(list)
for ab in AB:
    a, b = ab
    T[a].append(b)

P = defaultdict(int)
for px in PX:
    p, x = px
    P[p] += x
ans[1] = P[1]

for t in T[1]:
    q.append([1, t])
while q:
    a, b = q.popleft()
    ans[b] += ans[a] + P[b]
    for t in T[b]:
        q.append([b, t])

print(*ans[1:])


Fixed submission:
from collections import deque
from collections import defaultdict
import sys
readline = sys.stdin.readline

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

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

q = deque()
ans = [0] * (N+1)
ans[1] = P[1]

for t in T[1]:
    q.append([1, t])
while q:
    a, b = q.popleft()
    ans[b] += ans[a] + P[b]
    for c in T[b]:
        q.append([b, c])

print(*ans[1:])