Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(250000)
from collections import defaultdict

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

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

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

ans = [0 for _ in range(N + 1)]


def dfs(v, p, cnt):
    cnt += val[v]
    ans[v] = cnt
    for next_v in nl[v]:
        if next_v != p:
            dfs(next_v, v, cnt)


dfs(1, -1, 0)
c = [0 for _ in range(N + 1)]
print(' '.join([str(a) for a in ans[1:]]))


Fixed submission:
from collections import defaultdict

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

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

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

ans = [0 for _ in range(N + 1)]

stack = list()
stack.append((0, -1, 0))
while len(stack) > 0:
    v, p, cnt = stack.pop()
    cnt += val[v]
    ans[v] = cnt
    for next_v in nl[v]:
        if next_v != p:
            stack.append((next_v, v, cnt))

print(' '.join([str(a) for a in ans[1:]]))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(250000)
from collections import defaultdict

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

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

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

seen = set()
ans = [0 for _ in range(N + 1)]


def dfs(v, cnt):
    seen.add(v)
    cnt += val[v]
    ans[v] = cnt
    for next_v in nl[v]:
        if next_v not in seen:
            dfs(next_v, cnt)


dfs(1, 0)
c = [0 for _ in range(N + 1)]
print(' '.join([str(a) for a in ans[1:]]))


Fixed submission:
from collections import defaultdict

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

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

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

ans = [0 for _ in range(N + 1)]

stack = list()
stack.append((0, -1, 0))
while len(stack) > 0:
    v, p, cnt = stack.pop()
    cnt += val[v]
    ans[v] = cnt
    for next_v in nl[v]:
        if next_v != p:
            stack.append((next_v, v, cnt))

print(' '.join([str(a) for a in ans[1:]]))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(250000)

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

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

d = [[i] for i in range(N + 1)]
seen = set()


def dfs(v, parents):
    seen.add(v)
    for p in parents:
        d[p].append(v)
    for next_v in nl[v]:
        if next_v not in seen:
            dfs(next_v, parents + [v])


dfs(1, [])
c = [0 for _ in range(N + 1)]
for p, x in [tuple(map(int, input().split())) for _ in range(Q)]:
    for v in d[p]:
        c[v] += x
print(' '.join([str(ans) for ans in c[1:]]))

Fixed submission:
from collections import defaultdict

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

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

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

ans = [0 for _ in range(N + 1)]

stack = list()
stack.append((0, -1, 0))
while len(stack) > 0:
    v, p, cnt = stack.pop()
    cnt += val[v]
    ans[v] = cnt
    for next_v in nl[v]:
        if next_v != p:
            stack.append((next_v, v, cnt))

print(' '.join([str(a) for a in ans[1:]]))