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

l = [set() for i in range(N)]

for i in range(N-1):
  a, b = map(int, input().split())
  l[a-1].add(b-1)
  l[b-1].add(a-1)

par = [-1] * N
par[0] = 0

children = [[] for i in range(N)]

stack = [0]
while stack:
  prev = stack.pop()
  for to in l[prev]:
    if par[to] < 0:
      par[to] = prev
      children[prev].append(to)
      stack.append(to)

counter = [0] * N

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

r = [-1] * N
r[0] = counter[0]

stack = [0]
while stack:
  i = stack.pop()
  stack += children[i]
  s = 0
  cur = i
  while r[cur] < 0:
    s += counter[cur]
    cur = par[cur]
  r[i] = r[cur] + s

print(*r)

Fixed submission:
N, Q = map(int, input().split())

l = [[] for i in range(N)]

for i in range(N-1):
  a, b = map(int, input().split())
  l[a-1].append(b-1)
  l[b-1].append(a-1)

used = [False] * N
r = [0] * N

for i in range(Q):
  p, x = map(int, input().split())
  r[p-1] += x

stack = [0]
while stack:
  i = stack.pop()
  used[i] = True
  for to in l[i]:
    if not used[to]:
      stack.append(to)
      r[to] += r[i]

print(*r)

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

l = [set() for i in range(N)]

for i in range(N-1):
  a, b = map(int, input().split())
  l[a-1].add(b-1)
  l[b-1].add(a-1)

par = [-1] * N
par[0] = 0

stack = [0]
while stack:
  prev = stack.pop()
  for to in l[prev]:
    if par[to] < 0:
      par[to] = prev
      stack.append(to)

counter = [0] * N

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

r = [-1] * N
r[0] = counter[0]

for i in range(N):
  s = 0
  cur = i
  while r[cur] < 0:
    s += counter[cur]
    cur = par[cur]
  r[i] = r[cur] + s

print(*r)

Fixed submission:
N, Q = map(int, input().split())

l = [[] for i in range(N)]

for i in range(N-1):
  a, b = map(int, input().split())
  l[a-1].append(b-1)
  l[b-1].append(a-1)

used = [False] * N
r = [0] * N

for i in range(Q):
  p, x = map(int, input().split())
  r[p-1] += x

stack = [0]
while stack:
  i = stack.pop()
  used[i] = True
  for to in l[i]:
    if not used[to]:
      stack.append(to)
      r[to] += r[i]

print(*r)

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

l = [set() for i in range(N)]

for i in range(N-1):
  a, b = map(int, input().split())
  l[a-1].add(b-1)
  l[b-1].add(a-1)

par = [-1] * N
par[0] = 0

stack = [0]
while stack:
  prev = stack.pop()
  for to in l[prev]:
    if par[to] < 0:
      par[to] = prev
      stack.append(to)

counter = [0] * N

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

r = [-1] * N
r[0] = counter[0]

for i in range(N):
  s = 0
  cur = i
  while r[cur] < 0:
    s += counter[cur]
    cur = par[cur]
  r[i] = r[cur] + s

print(*r)

Fixed submission:
N, Q = map(int, input().split())

l = [[] for i in range(N)]

for i in range(N-1):
  a, b = map(int, input().split())
  l[a-1].append(b-1)
  l[b-1].append(a-1)

used = [False] * N
r = [0] * N

for i in range(Q):
  p, x = map(int, input().split())
  r[p-1] += x

stack = [0]
while stack:
  i = stack.pop()
  used[i] = True
  for to in l[i]:
    if not used[to]:
      stack.append(to)
      r[to] += r[i]

print(*r)