Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
dic = {}
amari = {}
for i in range(N-1):
  k, v = map(int, input().split())
  try:
    dic[k].append(v)
  except KeyError:
    dic[k] = [v]
  try:
    amari.pop(k)
  except KeyError:
    pass
  amari[v] = []
dic.update(amari)
counter = [list(map(int, input().split())) for i in range(Q)]
q = {i: 0 for i in dic.keys()}
 
def child_sum(q,v, child):
  if child == []:
    return q
  else:
    for j in child:
      q[j] += v
      child = dic[j]
      q = child_sum(q, v, child)
  return q
    
for i, v in counter:
  q[i] += v
  child = dic[i]
  #print(q, i, child)
  q = child_sum(q, v, child)
print(*q.values())

Fixed submission:
N, Q = map(int, input().split())
edge = [[] for i in range(N)]
q = [0 for i in range(N)]
 
for i in range(N-1):
  a, b = map(int, input().split())
  edge[a-1].append(b)
for i in range(Q):
  a, v = map(int, input().split())
  q[a-1] += v
 
for i, v in enumerate(q):
  #print(i, v)
  for j in edge[i]:
    #print(j)
    q[j-1] += v
print(*q)

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
dic = {}
amari = {}
for i in range(N-1):
  k, v = map(int, input().split())
  try:
    dic[k].append(v)
  except KeyError:
    dic[k] = [v]
  try:
    amari.pop(k)
  except:
    pass
  amari[v] = None
for i in amari.keys():
  dic[i] = []
counter = [list(map(int, input().split())) for i in range(Q)]
q = {i: 0 for i in dic.keys()}
 
def child_sum(q,v, child):
  if child == []:
    return q
  else:
    for j in child:
      q[j] += v
      child = dic[j]
      q = child_sum(q, v, child)
  return q
    
for i, v in counter:
  q[i] += v
  child = dic[i]
  #print(q, i, child)
  q = child_sum(q, v, child)
print(' '.join([str(i) for i in q.values()]))

Fixed submission:
N, Q = map(int, input().split())
edge = [[] for i in range(N)]
q = [0 for i in range(N)]
 
for i in range(N-1):
  a, b = map(int, input().split())
  edge[a-1].append(b)
for i in range(Q):
  a, v = map(int, input().split())
  q[a-1] += v
 
for i, v in enumerate(q):
  #print(i, v)
  for j in edge[i]:
    #print(j)
    q[j-1] += v
print(*q)

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
tree = [list(map(int, input().split())) for i in range(N-1)]
counter = [list(map(int, input().split())) for i in range(Q)]
dic = {}
for i in tree:
  try:
    dic[i[0]].append(i[1])
  except KeyError:
    dic[i[0]] = [i[1]]
keys = dic.keys()
for i in tree:
  if i[1] not in keys:
    dic[i[1]] = []
q = {i: 0 for i in dic.keys()}
 
def child_sum(q,v, child):
  if child == []:
    #print('test', q, v, child)
    return q
  else:
    for j in child:
      
      q[j] += v
      child = dic[j]
      #print('test2', j, v, child)
      q = child_sum(q, v, child)
  return q
    
for i, v in counter:
  q[i] += v
  child = dic[i]
  #print(q, i, child)
  q = child_sum(q, v, child)
print(' '.join([str(i) for i in q.values()]))


Fixed submission:
N, Q = map(int, input().split())
edge = [[] for i in range(N)]
q = [0 for i in range(N)]
 
for i in range(N-1):
  a, b = map(int, input().split())
  edge[a-1].append(b)
for i in range(Q):
  a, v = map(int, input().split())
  q[a-1] += v
 
for i, v in enumerate(q):
  #print(i, v)
  for j in edge[i]:
    #print(j)
    q[j-1] += v
print(*q)

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
tree = [list(map(int, input().split())) for i in range(N-1)]
counter = [list(map(int, input().split())) for i in range(Q)]
dic = {}
for i in tree:
  try:
    dic[i[0]].append(i[1])
  except KeyError:
    dic[i[0]] = [i[1]]
keys = dic.keys()
for i in tree:
  if i[1] not in keys:
    dic[i[1]] = []
q = {i: 0 for i in dic.keys()}

def child_sum(q,v, child):
  if child == []:
    #print('test', q, v, child)
    return q
  else:
    for j in child:
      
      q[j] += v
      child = dic[j]
      #print('test2', j, v, child)
      q = child_sum(q, v, child)
  return q
    
for i, v in counter:
  q[i] += v
  child = dic[i]
  #print(q, i, child)
  q = child_sum(q, v, child)


Fixed submission:
N, Q = map(int, input().split())
edge = [[] for i in range(N)]
q = [0 for i in range(N)]
 
for i in range(N-1):
  a, b = map(int, input().split())
  edge[a-1].append(b)
for i in range(Q):
  a, v = map(int, input().split())
  q[a-1] += v
 
for i, v in enumerate(q):
  #print(i, v)
  for j in edge[i]:
    #print(j)
    q[j-1] += v
print(*q)