Buggy python submission (verdict: Time Limit Exceeded):
class Node:
  def __init__(self):
    self.counter = 0
    self.childs = []
    self.parents = set()
  def add_child(self, node):
    self.childs.append(node)
  def add_parents(self, node):
    self.parents.add(node)

N, Q = [int(i) for i in input().split()]
ndic = {}
for i in range(1, N+1):
  ndic[i] = Node()
  ndic[i].add_child(ndic[i])
for i in range(N-1):
  a, b = [int(i) for i in input().split()]
  ndic[a].add_child(ndic[b])
  ndic[b].add_parents(ndic[a])
  for n in ndic[a].parents:
    n.add_child(ndic[b])  
    ndic[b].add_parents(n)

from collections import defaultdict
adddict = defaultdict(int)
for i in range(Q):
  p, x = [int(i) for i in input().split()]
  adddict[p] += x
for k, v in adddict.items():
  if v > 0:
    for j in ndic[k].childs:
      j.counter += v
ans = ""
for k, v in ndic.items():
  ans += str(v.counter) + " "
print(ans[:-1])

Fixed submission:
n, q = map(int, input().split())
 
tree = {i:[] for i in range(1, n + 1)}
for _ in range(1, n):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)
 
cnt = [0]*n
for _ in range(q):
    p, x = map(int, input().split())
    cnt[p-1] += x
 
check = [0]*n
 
tmp = [1]
while len(tmp) != 0:
    tmp2 = tmp
    tmp = []
    for oya in tmp2:
        check[int(oya)-1] = 1
        for ko in tree[oya]:
            if check[ko-1] == 0:
                cnt[ko-1] += cnt[oya-1]
                tmp.append(ko)
 
 
print(" ".join(map(str, cnt)))

Buggy python submission (verdict: Time Limit Exceeded):
class Node:
  def __init__(self):
    self.counter = 0
    self.childs = []
  def add_child(self, node):
    self.childs.append(node)

N, Q = [int(i) for i in input().split()]
ndic = {}
for i in range(1, N+1):
  ndic[i] = Node()
for i in range(N-1):
  a, b = [int(i) for i in input().split()]
  ndic[a].add_child(ndic[b])

for i in range(Q):
  p, x = [int(i) for i in input().split()]
  stack = []
  stack.append(ndic[p])
  while(len(stack) > 0):
    node = stack.pop()
    node.counter += x
    for n in node.childs:
      stack.append(n)
ans = ""
for k, v in ndic.items():
  ans += str(v.counter) + " "
print(ans[:-1])

Fixed submission:
n, q = map(int, input().split())
 
tree = {i:[] for i in range(1, n + 1)}
for _ in range(1, n):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)
 
cnt = [0]*n
for _ in range(q):
    p, x = map(int, input().split())
    cnt[p-1] += x
 
check = [0]*n
 
tmp = [1]
while len(tmp) != 0:
    tmp2 = tmp
    tmp = []
    for oya in tmp2:
        check[int(oya)-1] = 1
        for ko in tree[oya]:
            if check[ko-1] == 0:
                cnt[ko-1] += cnt[oya-1]
                tmp.append(ko)
 
 
print(" ".join(map(str, cnt)))

Buggy python submission (verdict: Time Limit Exceeded):
class Node:
  def __init__(self):
    self.counter = 0
    self.childs = []
  def add_child(self, node):
    self.childs.append(node)

N, Q = [int(i) for i in input().split()]
ndic = {}
for i in range(1, N+1):
  ndic[i] = Node()
for i in range(N-1):
  a, b = [int(i) for i in input().split()]
  ndic[a].add_child(ndic[b])

for i in range(Q):
  p, x = [int(i) for i in input().split()]
  stack = []
  stack.append(ndic[p])
  while(len(stack) > 0):
    node = stack.pop()
    node.counter += x
    for n in node.childs:
      stack.append(n)
ans = ""
for k, v in ndic.items():
  ans += str(v.counter) + " "
print(ans[:-1])

Fixed submission:
n, q = map(int, input().split())
 
tree = {i:[] for i in range(1, n + 1)}
for _ in range(1, n):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)
 
cnt = [0]*n
for _ in range(q):
    p, x = map(int, input().split())
    cnt[p-1] += x
 
check = [0]*n
 
tmp = [1]
while len(tmp) != 0:
    tmp2 = tmp
    tmp = []
    for oya in tmp2:
        check[int(oya)-1] = 1
        for ko in tree[oya]:
            if check[ko-1] == 0:
                cnt[ko-1] += cnt[oya-1]
                tmp.append(ko)
 
 
print(" ".join(map(str, cnt)))

Buggy python submission (verdict: Time Limit Exceeded):
class Node:
  def __init__(self):
    self.counter = 0
    self.childs = []
    self.parents = set()
  def add_child(self, node):
    self.childs.append(node)
  def add_parents(self, node):
    self.parents.add(node)

N, Q = [int(i) for i in input().split()]
ndic = {}
for i in range(1, N+1):
  ndic[i] = Node()
  ndic[i].add_child(ndic[i])
for i in range(N-1):
  a, b = [int(i) for i in input().split()]
  ndic[a].add_child(ndic[b])
  ndic[b].add_parents(ndic[a])
  for n in ndic[a].parents:
    n.add_child(ndic[b])  
    ndic[b].add_parents(n)

for i in range(Q):
  p, x = [int(i) for i in input().split()]
  for j in ndic[p].childs:
    j.counter += x
ans = ""
for k, v in ndic.items():
  ans += str(v.counter) + " "
print(ans[:-1])

Fixed submission:
n, q = map(int, input().split())
 
tree = {i:[] for i in range(1, n + 1)}
for _ in range(1, n):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)
 
cnt = [0]*n
for _ in range(q):
    p, x = map(int, input().split())
    cnt[p-1] += x
 
check = [0]*n
 
tmp = [1]
while len(tmp) != 0:
    tmp2 = tmp
    tmp = []
    for oya in tmp2:
        check[int(oya)-1] = 1
        for ko in tree[oya]:
            if check[ko-1] == 0:
                cnt[ko-1] += cnt[oya-1]
                tmp.append(ko)
 
 
print(" ".join(map(str, cnt)))