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

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

cnt = [0 for _ in range(N + 1)]
for _ in range(Q):
  p, x = map(int, input().split())
  cnt[p] += x

queue = [[1, 0]]
while len(queue) > 0:
  q = queue.pop(0)
  if q[0] != 0:
    cnt[q[0]] += cnt[q[1]]
  for i in to[q[0]]:
    if i != q[1]:
      queue.append([i, q[0]])

for i in range(1, N + 1):
  print(cnt[i])

Fixed submission:
from collections import deque
n, Q = map(int, input().split())
edges = [[] for _ in range(n+1)]
count = [0]*(n+1)
q = deque()
q.append((1, 0))

for _ in range(n-1):
    a, b = map(int, input().split())
    edges[a].append(b)
    edges[b].append(a)
for _ in range(Q):
    p, x = map(int, input().split())
    count[p] += x

while(q):
    k = q.popleft()
    count[k[0]] += count[k[1]]
    for i in edges[k[0]]:
        if not i == k[1]:
            q.append((i, k[0]))

print(*count[1:])

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

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

cnt = [0 for _ in range(N)]
for _ in range(Q):
  p, x = map(int, input().split())
  p -= 1
  cnt[p] += x

queue = [[0, -1]]
while len(queue) > 0:
  q = queue.pop(0)
  if q[0] != 0:
    cnt[q[0]] += cnt[q[1]]
  for i in to[q[0]]:
    if i != q[1]:
      queue.append([i, q[0]])

for c in cnt:
  print(c)

Fixed submission:
from collections import deque
n, Q = map(int, input().split())
edges = [[] for _ in range(n+1)]
count = [0]*(n+1)
q = deque()
q.append((1, 0))

for _ in range(n-1):
    a, b = map(int, input().split())
    edges[a].append(b)
    edges[b].append(a)
for _ in range(Q):
    p, x = map(int, input().split())
    count[p] += x

while(q):
    k = q.popleft()
    count[k[0]] += count[k[1]]
    for i in edges[k[0]]:
        if not i == k[1]:
            q.append((i, k[0]))

print(*count[1:])

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

N, Q = map(int, input().split())

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

cnt = [0 for _ in range(N)]
for _ in range(Q):
  p, x = map(int, input().split())
  p -= 1
  cnt[p] += x

queue = deque()
queue.append((0, -1))
while queue:
  q = queue.popleft()
  if q[0] != 0:
    cnt[q[0]] += cnt[q[1]]
  for i in to[q[0]]:
    if i != q[1]:
      queue.append((i, q[0]))

for i in range(N):
  print(cnt[i], end = "")
  if i == N - 1:
    print()
  else:
    print(" ", end = "")

Fixed submission:
from collections import deque
n, Q = map(int, input().split())
edges = [[] for _ in range(n+1)]
count = [0]*(n+1)
q = deque()
q.append((1, 0))

for _ in range(n-1):
    a, b = map(int, input().split())
    edges[a].append(b)
    edges[b].append(a)
for _ in range(Q):
    p, x = map(int, input().split())
    count[p] += x

while(q):
    k = q.popleft()
    count[k[0]] += count[k[1]]
    for i in edges[k[0]]:
        if not i == k[1]:
            q.append((i, k[0]))

print(*count[1:])

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

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

cnt = [0 for _ in range(N)]
for _ in range(Q):
  p, x = map(int, input().split())
  p -= 1
  cnt[p] += x

queue = [[0, -1]]
while len(queue) > 0:
  q = queue.pop(0)
  if q[0] != 0:
    cnt[q[0]] += cnt[q[1]]
  for i in to[q[0]]:
    if i != q[1]:
      queue.append([i, q[0]])

for i in range(N):
  print(cnt[i], end = "")
  if i == N - 1:
    print()
  else:
    print(" ", end = "")

Fixed submission:
from collections import deque
n, Q = map(int, input().split())
edges = [[] for _ in range(n+1)]
count = [0]*(n+1)
q = deque()
q.append((1, 0))

for _ in range(n-1):
    a, b = map(int, input().split())
    edges[a].append(b)
    edges[b].append(a)
for _ in range(Q):
    p, x = map(int, input().split())
    count[p] += x

while(q):
    k = q.popleft()
    count[k[0]] += count[k[1]]
    for i in edges[k[0]]:
        if not i == k[1]:
            q.append((i, k[0]))

print(*count[1:])

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

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

cnt = [0 for _ in range(N)]
for _ in range(Q):
  p, x = map(int, input().split())
  p -= 1
  cnt[p] += x

queue = [[0, -1]]
while len(queue) > 0:
  q = queue.pop(0)
  if q[0] != 0:
    cnt[q[0]] += cnt[q[1]]
  for i in to[q[0]]:
    if i != q[1]:
      queue.append([i, q[0]])

for i in range(N):
  print(cnt[i], end = "")
  if i == N - 1:
    print()
  else:
    print(" ", end = "")

Fixed submission:
from collections import deque
n, Q = map(int, input().split())
edges = [[] for _ in range(n+1)]
count = [0]*(n+1)
q = deque()
q.append((1, 0))

for _ in range(n-1):
    a, b = map(int, input().split())
    edges[a].append(b)
    edges[b].append(a)
for _ in range(Q):
    p, x = map(int, input().split())
    count[p] += x

while(q):
    k = q.popleft()
    count[k[0]] += count[k[1]]
    for i in edges[k[0]]:
        if not i == k[1]:
            q.append((i, k[0]))

print(*count[1:])

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

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

queue = [0]
parent = [0 for _ in range(N)]
while len(queue) > 0:
  q = queue.pop(0)
  for br in to[q]:
    to[br].remove(q)
    parent[br] = q
    queue.append(br)

cnt = [0 for _ in range(N)]
for _ in range(Q):
  p, x = map(int, input().split())
  p -= 1
  cnt[p] += x

queue = [0]
while len(queue) > 0:
  q = queue.pop(0)
  if q != 0:
    cnt[q] += cnt[parent[q]]
  for br in to[q]:
    queue.append(br)

for i in range(N):
  print(cnt[i], end = "")
  if i == N - 1:
    print()
  else:
    print(" ", end = "")

Fixed submission:
from collections import deque
n, Q = map(int, input().split())
edges = [[] for _ in range(n+1)]
count = [0]*(n+1)
q = deque()
q.append((1, 0))

for _ in range(n-1):
    a, b = map(int, input().split())
    edges[a].append(b)
    edges[b].append(a)
for _ in range(Q):
    p, x = map(int, input().split())
    count[p] += x

while(q):
    k = q.popleft()
    count[k[0]] += count[k[1]]
    for i in edges[k[0]]:
        if not i == k[1]:
            q.append((i, k[0]))

print(*count[1:])

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

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

queue = [0]
parent = [[] for _ in range(N)]
while len(queue) > 0:
  q = queue.pop(0)
  for br in to[q]:
    to[br].remove(q)
    parent[br].append(q)
    queue.append(br)

cnt = [0 for _ in range(N)]
for _ in range(Q):
  p, x = map(int, input().split())
  p -= 1
  cnt[p] += x

queue = [0]
while len(queue) > 0:
  q = queue.pop(0)
  if q != 0:
    cnt[q] += cnt[parent[q][0]]
  for br in to[q]:
    queue.append(br)

for i in range(N):
  print(cnt[i], end = "")
  if i == N - 1:
    print()
  else:
    print(" ", end = "")

Fixed submission:
from collections import deque
n, Q = map(int, input().split())
edges = [[] for _ in range(n+1)]
count = [0]*(n+1)
q = deque()
q.append((1, 0))

for _ in range(n-1):
    a, b = map(int, input().split())
    edges[a].append(b)
    edges[b].append(a)
for _ in range(Q):
    p, x = map(int, input().split())
    count[p] += x

while(q):
    k = q.popleft()
    count[k[0]] += count[k[1]]
    for i in edges[k[0]]:
        if not i == k[1]:
            q.append((i, k[0]))

print(*count[1:])

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

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

queue = [0]
parent = [[] for _ in range(N)]
while len(queue) > 0:
  q = queue.pop(0)
  for br in to[q]:
    to[br].remove(q)
    parent[br].append(q)
    queue.append(br)

cnt = [0 for _ in range(N)]
for _ in range(Q):
  p, x = map(int, input().split())
  p -= 1
  cnt[p] += x

queue = [0]
while len(queue) > 0:
  q = queue.pop(0)
  if q != 0:
    cnt[q] += cnt[parent[q][0]]
  for br in to[q]:
    queue.append(br)

for i in range(N):
  print(cnt[i], end = "")
  if i == N - 1:
    print()
  else:
    print(" ", end = "")

Fixed submission:
from collections import deque
n, Q = map(int, input().split())
edges = [[] for _ in range(n+1)]
count = [0]*(n+1)
q = deque()
q.append((1, 0))

for _ in range(n-1):
    a, b = map(int, input().split())
    edges[a].append(b)
    edges[b].append(a)
for _ in range(Q):
    p, x = map(int, input().split())
    count[p] += x

while(q):
    k = q.popleft()
    count[k[0]] += count[k[1]]
    for i in edges[k[0]]:
        if not i == k[1]:
            q.append((i, k[0]))

print(*count[1:])

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

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

queue = [0]
branch = [[i] for i in range(N)]
parent = [[] for _ in range(N)]
while len(queue) > 0:
  q = queue.pop(0)
  for br in to[q]:
    branch[q].append(br)
    to[br].remove(q)
    parent[br].append(q)
    for p in parent[q]:
      parent[br].append(p)
    queue.append(br)

for i in range(1, N):
  for p in parent[i]:
    if not i in branch[p]:
      branch[p].append(i)

cnt = [0 for _ in range(N)]
for _ in range(Q):
  p, x = map(int, input().split())
  p -= 1
  for b in branch[p]:
    cnt[b] += x

for i in range(N):
  print(cnt[i], end = "")
  if i == N - 1:
    print()
  else:
    print(" ", end = "")

Fixed submission:
from collections import deque
n, Q = map(int, input().split())
edges = [[] for _ in range(n+1)]
count = [0]*(n+1)
q = deque()
q.append((1, 0))

for _ in range(n-1):
    a, b = map(int, input().split())
    edges[a].append(b)
    edges[b].append(a)
for _ in range(Q):
    p, x = map(int, input().split())
    count[p] += x

while(q):
    k = q.popleft()
    count[k[0]] += count[k[1]]
    for i in edges[k[0]]:
        if not i == k[1]:
            q.append((i, k[0]))

print(*count[1:])

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

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

queue = [0]
branch = [[i] for i in range(N)]
parent = [[] for _ in range(N)]
while len(queue) > 0:
  q = queue.pop(0)
  for br in to[q]:
    branch[q].append(br)
    to[br].remove(q)
    parent[br].append(q)
    for p in parent[q]:
      parent[br].append(p)
    queue.append(br)

for i in range(1, N):
  for p in parent[i]:
    if not i in branch[p]:
      branch[p].append(i)

cnt = [0 for _ in range(N)]
for _ in range(Q):
  p, x = map(int, input().split())
  p -= 1
  for b in branch[p]:
    cnt[b] += x

for i in range(N):
  print(cnt[i], end = "")
  if i == N - 1:
    print()
  else:
    print(" ", end = "")

Fixed submission:
from collections import deque
n, Q = map(int, input().split())
edges = [[] for _ in range(n+1)]
count = [0]*(n+1)
q = deque()
q.append((1, 0))

for _ in range(n-1):
    a, b = map(int, input().split())
    edges[a].append(b)
    edges[b].append(a)
for _ in range(Q):
    p, x = map(int, input().split())
    count[p] += x

while(q):
    k = q.popleft()
    count[k[0]] += count[k[1]]
    for i in edges[k[0]]:
        if not i == k[1]:
            q.append((i, k[0]))

print(*count[1:])