Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000)
def add_to_subtree(tree, result_arr, idx, value):
  result_arr[idx] += value
  if len(tree[idx]) == 0:
    return
  for child in tree[idx]:
    add_to_subtree(tree, result_arr, child, value)

N, Q = map(int, input().split())
R = [0] * (N + 1)
T = [[] for _ in range(N + 1)]

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

print(*R[1:])


Fixed submission:
import collections
N, Q = map(int, input().split())
counts = [0] * (N + 1)
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)
for _ in range(Q):
  p, x = map(int, input().split())
  counts[p] += x
visited = [0] * (N + 1)
queue = collections.deque()
queue.append(1)
while queue:
  v = queue.pop()
  visited[v] = 1
  x = counts[v]
  for child in T[v]:
    if visited[child] == 1:
      continue
    counts[child] += x
    queue.append(child)
print(*counts[1:])

Buggy python submission (verdict: Runtime Error):
def add_to_subtree(tree, result_arr, idx, value):
  result_arr[idx] += value
  if len(tree[idx]) == 0:
    return
  for child in tree[idx]:
    add_to_subtree(tree, result_arr, child, value)

N, Q = map(int, input().split())
R = [0] * (N + 1)
T = [[] for _ in range(N + 1)]

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

print(*R[1:])


Fixed submission:
import collections
N, Q = map(int, input().split())
counts = [0] * (N + 1)
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)
for _ in range(Q):
  p, x = map(int, input().split())
  counts[p] += x
visited = [0] * (N + 1)
queue = collections.deque()
queue.append(1)
while queue:
  v = queue.pop()
  visited[v] = 1
  x = counts[v]
  for child in T[v]:
    if visited[child] == 1:
      continue
    counts[child] += x
    queue.append(child)
print(*counts[1:])

Buggy python submission (verdict: Runtime Error):
def add_to_subtree(tree, result_arr, idx, value):
  result_arr[idx] += value
  if len(tree[idx]) == 0:
    return
  for child in tree[idx]:
    add_to_subtree(tree, result_arr, child, value)

N, Q = map(int, input().split())
T = [[] for i in range(N + 1)]
R = [0] * (N + 1)
for _ in range(N-1):
  a, b = map(int, input().split())
  T[a].append(b)
for _ in range(Q):
  P, X = map(int, input().split())
  add_to_subtree(T, R, P, X)

print(" ".join(map(str, R[1:])))


Fixed submission:
import collections
N, Q = map(int, input().split())
counts = [0] * (N + 1)
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)
for _ in range(Q):
  p, x = map(int, input().split())
  counts[p] += x
visited = [0] * (N + 1)
queue = collections.deque()
queue.append(1)
while queue:
  v = queue.pop()
  visited[v] = 1
  x = counts[v]
  for child in T[v]:
    if visited[child] == 1:
      continue
    counts[child] += x
    queue.append(child)
print(*counts[1:])