Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

n, m= map(int, input().split())

links = [deque() for x in range(n + 1)]
sums = [0 for x in range(n + 1)]
adds = [0 for x in range(n + 1)]

links[0].append(1)
for _ in range(n - 1):
  a, b= map(int, input().split())
  links[a].append(b)
  links[b].append(a)

for _ in range(m):
  p, x = map(int, input().split())
  adds[p] += x

que = [0,[1]]
checked = [0 for x in range(n+1)]

que = [[-1, [0]]]

while que:
  link = que.pop()
  par = link[0]
  childs = link[1]

  for child in childs:
    if checked[child] != 1:
      sums[child] = sums[par] + adds[child]
      que.append([child, links[child]])
      checked[child] = 1

  
print(*sums[1:])

Fixed submission:
from collections import defaultdict

n, m= map(int, input().split())

links = [[] for x in range(n + 1)]
sums = [0 for x in range(n + 1)]
adds = [0 for x in range(n + 1)]

links[0].append(1)
for _ in range(n - 1):
  a, b= map(int, input().split())
  links[a].append(b)
  links[b].append(a)

for _ in range(m):
  p, x = map(int, input().split())
  adds[p] += x

# print(links)
que = [0,[1]]
checked = [0 for x in range(n+1)]

que = [[-1, [0]]]

while que:
  link = que.pop()
  # print(link)
  par = link[0]
  childs = link[1]

  for child in childs:
    if checked[child] != 1:
      sums[child] = sums[par] + adds[child]
      que.append([child, links[child]])
      checked[child] = 1

  
print(*sums[1:])

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

n, m= map(int, input().split())

links = []

sums = np.zeros(n + 1)

oya = {}

for _ in range(n - 1):
  a, b= map(int, input().split())
  oya[b] = a
  heapq.heappush(links, [a, b])

uppers = np.eye(n + 1)

for l in links:
  oyaId = l[0]
  koId = l[1]
  uppers[oyaId, koId] = 1
  while True: 
    if oyaId in oya:
      uppers[oyaId, koId] = 1
      oyaId = oya[oyaId]
    else:
      uppers[oyaId, koId] = 1
      break
      
for _ in range(m):
  p, x = map(int, input().split())
  sums += x * uppers[p, :]
print(*sums[1:].astype(np.int))
  

Fixed submission:
from collections import defaultdict

n, m= map(int, input().split())

links = [[] for x in range(n + 1)]
sums = [0 for x in range(n + 1)]
adds = [0 for x in range(n + 1)]

links[0].append(1)
for _ in range(n - 1):
  a, b= map(int, input().split())
  links[a].append(b)
  links[b].append(a)

for _ in range(m):
  p, x = map(int, input().split())
  adds[p] += x

# print(links)
que = [0,[1]]
checked = [0 for x in range(n+1)]

que = [[-1, [0]]]

while que:
  link = que.pop()
  # print(link)
  par = link[0]
  childs = link[1]

  for child in childs:
    if checked[child] != 1:
      sums[child] = sums[par] + adds[child]
      que.append([child, links[child]])
      checked[child] = 1

  
print(*sums[1:])

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

n, m= map(int, input().split())

links = []

sums = np.zeros(n + 1)

oya = {}

for _ in range(n - 1):
  a, b= map(int, input().split())
  oya[b] = a
  heapq.heappush(links, [a, b])

uppers = np.eye(n + 1)

for l in links:
  oyaId = l[0]
  koId = l[1]

  while True: 
    uppers[oyaId, koId] = 1
    if oyaId != 1:
      oyaId = oya[oyaId]
    else:
      break
      
for _ in range(m):
  p, x = map(int, input().split())
  sums += x * uppers[p, :]
print(*sums[1:].astype(np.int))
  

Fixed submission:
from collections import defaultdict

n, m= map(int, input().split())

links = [[] for x in range(n + 1)]
sums = [0 for x in range(n + 1)]
adds = [0 for x in range(n + 1)]

links[0].append(1)
for _ in range(n - 1):
  a, b= map(int, input().split())
  links[a].append(b)
  links[b].append(a)

for _ in range(m):
  p, x = map(int, input().split())
  adds[p] += x

# print(links)
que = [0,[1]]
checked = [0 for x in range(n+1)]

que = [[-1, [0]]]

while que:
  link = que.pop()
  # print(link)
  par = link[0]
  childs = link[1]

  for child in childs:
    if checked[child] != 1:
      sums[child] = sums[par] + adds[child]
      que.append([child, links[child]])
      checked[child] = 1

  
print(*sums[1:])

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

n, m= map(int, input().split())

links = []

sums = np.zeros(n + 1)

oya = {}

for _ in range(n - 1):
  a, b= map(int, input().split())
  oya[b] = a
  heapq.heappush(links, [a, b])

uppers = np.eye(n + 1)

for l in links:
  oyaId = l[0]
  koId = l[1]

  while True: 
    uppers[oyaId, koId] = 1
    if oyaId in oya:
      oyaId = oya[oyaId]
    else:
      break
# print(uppers)
# print(sums)
for _ in range(m):
  p, x = map(int, input().split())
  sums += x * uppers[p, :]
print(*sums[1:].astype(np.int))
  

Fixed submission:
from collections import defaultdict

n, m= map(int, input().split())

links = [[] for x in range(n + 1)]
sums = [0 for x in range(n + 1)]
adds = [0 for x in range(n + 1)]

links[0].append(1)
for _ in range(n - 1):
  a, b= map(int, input().split())
  links[a].append(b)
  links[b].append(a)

for _ in range(m):
  p, x = map(int, input().split())
  adds[p] += x

# print(links)
que = [0,[1]]
checked = [0 for x in range(n+1)]

que = [[-1, [0]]]

while que:
  link = que.pop()
  # print(link)
  par = link[0]
  childs = link[1]

  for child in childs:
    if checked[child] != 1:
      sums[child] = sums[par] + adds[child]
      que.append([child, links[child]])
      checked[child] = 1

  
print(*sums[1:])

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

links = []

sums = [0] * (n + 1)

for _ in range(n - 1):
  a, b= map(int, input().split())
  heapq.heappush(links, [a,b])

uppers = [[x] for x in range(n + 1)]
oya = {}
for l in links:
  # uppers[l[0]].append(l[1])
  oya[l[1]] = l[0]
  up = l[0]
  while True:
    if up not in oya:
      # print(up)
      uppers[up].append(l[1])
      break
    else:
      uppers[up].append(l[1])
      up = oya[up]
# print(uppers)
# print(oya)

for _ in range(m):
  p, x = map(int, input().split())
  for up in uppers[p]:
    sums[up] += x

print(*sums[1:])
  

Fixed submission:
from collections import defaultdict

n, m= map(int, input().split())

links = [[] for x in range(n + 1)]
sums = [0 for x in range(n + 1)]
adds = [0 for x in range(n + 1)]

links[0].append(1)
for _ in range(n - 1):
  a, b= map(int, input().split())
  links[a].append(b)
  links[b].append(a)

for _ in range(m):
  p, x = map(int, input().split())
  adds[p] += x

# print(links)
que = [0,[1]]
checked = [0 for x in range(n+1)]

que = [[-1, [0]]]

while que:
  link = que.pop()
  # print(link)
  par = link[0]
  childs = link[1]

  for child in childs:
    if checked[child] != 1:
      sums[child] = sums[par] + adds[child]
      que.append([child, links[child]])
      checked[child] = 1

  
print(*sums[1:])

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

links = []

sums = [0] * (n + 1)

for _ in range(n - 1):
  a, b= map(int, input().split())
  heapq.heappush(links, [a,b])

uppers = [[1, x] for x in range(n + 1)]

for l in links:
  # print(l, uppers)
  uppers[l[1]] += uppers[l[0]]
  uppers[l[1]] = list(set(uppers[l[1]]))
  
for _ in range(m):
  p, x = map(int, input().split())
  for i in range(n+1):
    if p in uppers[i]:
      sums[i] += x

print(*sums[1:])
  

Fixed submission:
from collections import defaultdict

n, m= map(int, input().split())

links = [[] for x in range(n + 1)]
sums = [0 for x in range(n + 1)]
adds = [0 for x in range(n + 1)]

links[0].append(1)
for _ in range(n - 1):
  a, b= map(int, input().split())
  links[a].append(b)
  links[b].append(a)

for _ in range(m):
  p, x = map(int, input().split())
  adds[p] += x

# print(links)
que = [0,[1]]
checked = [0 for x in range(n+1)]

que = [[-1, [0]]]

while que:
  link = que.pop()
  # print(link)
  par = link[0]
  childs = link[1]

  for child in childs:
    if checked[child] != 1:
      sums[child] = sums[par] + adds[child]
      que.append([child, links[child]])
      checked[child] = 1

  
print(*sums[1:])