Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)

# from collections import defaultdict
def dfs(node_i):
    is_visited[node_i] = 1
    for bi in tree[node_i]:
        if is_visited[bi]:
            continue
        tree_x[bi] += tree_x[node_i]
        dfs(bi)

N, Q = map(int, input().split())
tree = [[] for i in range(N)]
# tree = defaultdict(list)
tree_x = [0]*N
is_visited = [0]*N
for i in range(N-1):
    a, b = map(int, input().split())
    am1 = a-1
    bm1 = b-1
    tree[bm1].append(am1)
    tree[am1].append(bm1)

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

dfs(0)

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


Fixed submission:
N, Q = map(int, input().split())
tree = [[] for i in range(N+1)]
counter = [0] * (N+1)

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

for i in range(Q):
    p, x = map(int, input().split())
    counter[p] += x
for i in range(1, N+1):
    for pn in tree[i]:
        counter[i] += counter[pn]

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

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)

from collections import defaultdict
def dfs(node_i):
    is_visited[node_i] = 1
    for bi in tree[node_i]:
        if is_visited[bi]:
            continue
        tree_x[bi] += tree_x[node_i]
        dfs(bi)

N, Q = map(int, input().split())
# tree = [[] for i in range(N)]
tree = defaultdict(list)
tree_x = [0 for i in range(N)]
is_visited = [0]*N
for i in range(N-1):
    a, b = map(int, input().split())
    am1 = a-1
    bm1 = b-1
    tree[bm1].append(am1)
    tree[am1].append(bm1)

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

dfs(0)

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


Fixed submission:
N, Q = map(int, input().split())
tree = [[] for i in range(N+1)]
counter = [0] * (N+1)

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

for i in range(Q):
    p, x = map(int, input().split())
    counter[p] += x
for i in range(1, N+1):
    for pn in tree[i]:
        counter[i] += counter[pn]

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

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
def dfs(node_i):
    is_visited[node_i] = 1
    for bi in tree[node_i]:
        if is_visited[bi]:
            continue
        tree_x[bi] += tree_x[node_i]
        dfs(bi)

N, Q = map(int, input().split())
# tree = [[] for i in range(N)]
tree = defaultdict(list)
tree_x = [0 for i in range(N)]
is_visited = [0]*N
for i in range(N-1):
    a, b = map(int, input().split())
    am1 = a-1
    bm1 = b-1
    tree[bm1].append(am1)
    tree[am1].append(bm1)

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

dfs(0)

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


Fixed submission:
N, Q = map(int, input().split())
tree = [[] for i in range(N+1)]
counter = [0] * (N+1)

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

for i in range(Q):
    p, x = map(int, input().split())
    counter[p] += x
for i in range(1, N+1):
    for pn in tree[i]:
        counter[i] += counter[pn]

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