Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())

tree = {}
for _ in range(n-1):
  a , b = map(lambda x:int(x)-1, input().split())
  if a not in tree:
    tree[a] = [b]
  else:
    tree[a].append(b)
  if b not in tree:
    tree[b] = [a]
  else:
    tree[b].append(a)

ans = [0]*n
for _ in range(q):
  p, x = map(int, input().split())
  ans[p-1] += x
  
will_go = [0]
already = []
for i in range(n):
  while will_go:
    now = will_go.pop()
    already.append(now)
    tmp = ans[now]
    for root in tree[now]:
      if root not in already:
        ans[root] += tmp
        will_go.append(root)
        
print(*ans)

Fixed submission:
n, q = map(int, input().split())

tree = {}
for _ in range(n-1):
  a , b = map(lambda x:int(x)-1, input().split())
  if a not in tree:
    tree[a] = [b]
  else:
    tree[a].append(b)
  if b not in tree:
    tree[b] = [a]
  else:
    tree[b].append(a)

ans = [0]*n
ald = [True]*n
for _ in range(q):
  p, x = map(int, input().split())
  ans[p-1] += x
  
will_go = [0]
ald[0] = False
for i in range(n):
  while will_go:
    now = will_go.pop()
    tmp = ans[now]
    for root in tree[now]:
      if ald[root]:
        ald[root] = False
        ans[root] += tmp
        will_go.append(root)
        
print(*ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())

tree = {}
for _ in range(n-1):
  a , b = map(lambda x:int(x)-1, input().split())
  if a not in tree:
    tree[a] = [b]
  else:
    tree[a].append(b)
  if b not in tree:
    tree[b] = [a]
  else:
    tree[b].append(a)

ans = [0]*n
for _ in range(q):
  p, x = map(int, input().split())
  ans[p-1] += x
  
will_go = [0]
already = []
for i in range(n):
  while will_go:
    now = will_go.pop()
    already.append(now)
    tmp = ans[now]
    if now in tree:
      for root in tree[now]:
        if root not in already:
          ans[root] += tmp
          will_go.append(root)
        
print(*ans)

Fixed submission:
n, q = map(int, input().split())

tree = {}
for _ in range(n-1):
  a , b = map(lambda x:int(x)-1, input().split())
  if a not in tree:
    tree[a] = [b]
  else:
    tree[a].append(b)
  if b not in tree:
    tree[b] = [a]
  else:
    tree[b].append(a)

ans = [0]*n
ald = [True]*n
for _ in range(q):
  p, x = map(int, input().split())
  ans[p-1] += x
  
will_go = [0]
ald[0] = False
for i in range(n):
  while will_go:
    now = will_go.pop()
    tmp = ans[now]
    for root in tree[now]:
      if ald[root]:
        ald[root] = False
        ans[root] += tmp
        will_go.append(root)
        
print(*ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())

tree = {}

tmp = [list(map(lambda x:int(x)-1, input().split())) for _ in range(n-1)]
will_go = [0]
already = []

while will_go:
  tmp2 = []
  now = will_go.pop()
  already.append(now)
  for node in tmp:
    if (now == node[0]) & (node[1] not in already):
      will_go.append(node[1])
      if now not in tree:
        tree[now] = [node[1]]
      else:
        tree[now].append(node[1])
    if (now == node[1]) & (node[0] not in already):
      will_go.append(node[0])
      if now not in tree:
        tree[now] = [node[0]]
      else:
        tree[now].append(node[0])
    else:
      tmp2.append(node)
  tmp = [i for i in tmp2]

ans = [0]*n
for _ in range(q):
  p, x = map(int, input().split())
  ans[p-1] += x
  
will_go = [0]
for i in range(n):
  while will_go:
    now = will_go.pop()
    tmp = ans[now]
    if now in tree:
      for root in tree[now]:
        ans[root] += tmp
        will_go.append(root)
        
print(*ans)

Fixed submission:
n, q = map(int, input().split())

tree = {}
for _ in range(n-1):
  a , b = map(lambda x:int(x)-1, input().split())
  if a not in tree:
    tree[a] = [b]
  else:
    tree[a].append(b)
  if b not in tree:
    tree[b] = [a]
  else:
    tree[b].append(a)

ans = [0]*n
ald = [True]*n
for _ in range(q):
  p, x = map(int, input().split())
  ans[p-1] += x
  
will_go = [0]
ald[0] = False
for i in range(n):
  while will_go:
    now = will_go.pop()
    tmp = ans[now]
    for root in tree[now]:
      if ald[root]:
        ald[root] = False
        ans[root] += tmp
        will_go.append(root)
        
print(*ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())

tree = {}
tmp = [list(map(lambda x:int(x)-1, input().split())) for _ in range(n-1)]
will_go = [0]
already = []
while will_go:
  now = will_go.pop()
  already.append(now)
  for node in tmp:
    if (now == node[0]) & (node[1] not in already):
      will_go.append(node[1])
      if now not in tree:
        tree[now] = [node[1]]
      else:
        tree[now].append(node[1])
    if (now == node[1]) & (node[0] not in already):
      will_go.append(node[0])
      if now not in tree:
        tree[now] = [node[0]]
      else:
        tree[now].append(node[0])

ans = [0]*n
for _ in range(q):
  p, x = map(int, input().split())
  ans[p-1] += x
  
will_go = [0]
for i in range(n):
  while will_go:
    now = will_go.pop()
    tmp = ans[now]
    if now in tree:
      for root in tree[now]:
        ans[root] += tmp
        will_go.append(root)
        
print(*ans)

Fixed submission:
n, q = map(int, input().split())

tree = {}
for _ in range(n-1):
  a , b = map(lambda x:int(x)-1, input().split())
  if a not in tree:
    tree[a] = [b]
  else:
    tree[a].append(b)
  if b not in tree:
    tree[b] = [a]
  else:
    tree[b].append(a)

ans = [0]*n
ald = [True]*n
for _ in range(q):
  p, x = map(int, input().split())
  ans[p-1] += x
  
will_go = [0]
ald[0] = False
for i in range(n):
  while will_go:
    now = will_go.pop()
    tmp = ans[now]
    for root in tree[now]:
      if ald[root]:
        ald[root] = False
        ans[root] += tmp
        will_go.append(root)
        
print(*ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())

tree = {}

tmp = [list(map(lambda x:int(x)-1, input().split())) for _ in range(n-1)]
will_go = [0]
already = []
while will_go:
  now = will_go.pop()
  already.append(now)
  for node in tmp:
    if (now == node[0]) & (node[1] not in already):
      will_go.append(node[1])
      if now not in tree:
        tree[now] = [node[1]]
      else:
        tree[now].append(node[1])
    if (now == node[1]) & (node[0] not in already):
      will_go.append(node[0])
      if now not in tree:
        tree[now] = [node[0]]
      else:
        tree[now].append(node[0])

ans = [0]*n
for _ in range(q):
  p, x = map(int, input().split())
  ans[p-1] += x
  
will_go = [0]
for i in range(n):
  while will_go:
    now = will_go.pop()
    tmp = ans[now]
    if now in tree:
      for root in tree[now]:
        ans[root] += tmp
        will_go.append(root)
        
print(*ans)

Fixed submission:
n, q = map(int, input().split())

tree = {}
for _ in range(n-1):
  a , b = map(lambda x:int(x)-1, input().split())
  if a not in tree:
    tree[a] = [b]
  else:
    tree[a].append(b)
  if b not in tree:
    tree[b] = [a]
  else:
    tree[b].append(a)

ans = [0]*n
ald = [True]*n
for _ in range(q):
  p, x = map(int, input().split())
  ans[p-1] += x
  
will_go = [0]
ald[0] = False
for i in range(n):
  while will_go:
    now = will_go.pop()
    tmp = ans[now]
    for root in tree[now]:
      if ald[root]:
        ald[root] = False
        ans[root] += tmp
        will_go.append(root)
        
print(*ans)