Buggy python submission (verdict: Runtime Error):
import numpy as np

N, Q = list(map(int, input().split()))
tree = np.eye(N)

for i in range(N-1):
  a, b = list(map(int, input().split()))
  ids = tree[:, a-1] > 0
  tree[ids, b-1] = 1
  
r = np.zeros(N)
for i in range(Q):
  p, x = list(map(int, input().split()))
  r += (tree[p-1] > 0)*x
  
r = np.array(r, dtype=int)
print(' '.join(map(str, r)))

Fixed submission:
from collections import deque

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

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

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

d = deque([[1, 0]])
while d:
  node, parent = d.popleft()
  counter[node] += counter[parent]
  children = tree[node]
  for child in children:
    if child == parent:
      continue
      
    d.append([child, node])
    
  
print(' '.join(map(str, counter[1:])))

Buggy python submission (verdict: Runtime Error):
import numpy as np

N, Q = list(map(int, input().split()))
tree = np.eye(N)

for i in range(N-1):
  a, b = list(map(int, input().split()))
  ids = tree[:, a-1] > 0
  tree[ids, b-1] = 1
  
r = np.zeros(N)
for i in range(Q):
  p, x = list(map(int, input().split()))
  r += (tree[p-1] > 0)*x
  
out = str(int(r[0]))
for i in range(1, N):
  out += ' {0}'.format(int(r[i]))

print(out)

Fixed submission:
from collections import deque

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

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

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

d = deque([[1, 0]])
while d:
  node, parent = d.popleft()
  counter[node] += counter[parent]
  children = tree[node]
  for child in children:
    if child == parent:
      continue
      
    d.append([child, node])
    
  
print(' '.join(map(str, counter[1:])))

Buggy python submission (verdict: Runtime Error):
def f(p, x, r, tree):
  r[p-1] += x
  children = tree[p]
  for child in children:
    r = f(child, x, r, tree)
  
  return r

N, Q = list(map(int, input().split()))
keys = [i for i in range(1, N+1)]
values = [[] for i in range(N)]
tree = dict(zip(keys, values))

for i in range(N-1):
  a, b = list(map(int, input().split()))
  if a in tree.keys():
    tree[a] += [b]
  
  else:
    tree[a] = [b]

r = [0 for i in range(N)]    
for i in range(Q):
  p, x = list(map(int, input().split()))
  r = f(p, x, r, tree)

out = str(r[0])
for i in range(1, N):
  out += ' {0}'.format(r[i])

print(out)

Fixed submission:
from collections import deque

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

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

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

d = deque([[1, 0]])
while d:
  node, parent = d.popleft()
  counter[node] += counter[parent]
  children = tree[node]
  for child in children:
    if child == parent:
      continue
      
    d.append([child, node])
    
  
print(' '.join(map(str, counter[1:])))