Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n, q = map(int, input().split())
node = [[] for _ in range(n)]
for i in range(n-1):
  a, b = map(int, input().split())
  node[a-1].append([a-1, b-1])
  node[b-1].append([b-1, a-1])

ans = [0]*n
for i in range(q):
  p, x = map(int, input().split())
  ans[p-1] += x

already = [False]*n
not_yet = deque(node[0])
already[0] = True
for i in not_yet:
  already[i[1]] = True
while not_yet:
  key = not_yet.popleft()
  a, b = key[0], key[1]
  already[b] = True
  ans[b] += ans[a]
  for i in range(len(node[b])):
    p, q = node[b][i][0], node[b][i][1]
    if already[q]:
      continue
    not_yet.append(node[b][i])
    already[q] = True
  
print(*ans)

Fixed submission:
from collections import deque

def main():
    n, q = map(int, input().split())
    tree = [[] for _ in range(n)]
    for i in range(n-1):
        a, b = map(int, input().split())
        tree[a-1].append(b-1)
        tree[b-1].append(a-1)
    
    ans = [0]*n
    for _ in range(q):
        p, x = map(int, input().split())
        ans[p-1] += x
    
    not_yet = deque([0])
    already = [False]*n
    already[0] = True
    
    while not_yet:
        key = not_yet.popleft()
        for value in tree[key]:
            if already[value]:
                continue
            already[value] = True
            not_yet.append(value)
            ans[value] += ans[key]
    
    print(*ans)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n, q = map(int, input().split())
node = [[] for _ in range(n)]
for i in range(n-1):
  a, b = map(int, input().split())
  node[a-1].append([a-1, b-1])
  node[b-1].append([b-1, a-1])

ans = [0]*n
for i in range(q):
  p, x = map(int, input().split())
  ans[p-1] += x

already = [[False]*n for i in range(n)]
not_yet = deque(node[0])
for k in not_yet:
  a, b = k[0], k[1]
  already[a][b] = True
  already[b][a] = True
while not_yet:
  key = not_yet.popleft()
  a, b = key[0], key[1]
  ans[b] += ans[a]
  for i in range(len(node[b])):
    p, q = node[b][i][0], node[b][i][1]
    if already[p][q] or already[p][q]:
      continue
    not_yet.append(node[b][i])
    already[p][q] = True
    already[q][p] = True
  
print(*ans)

Fixed submission:
from collections import deque

def main():
    n, q = map(int, input().split())
    tree = [[] for _ in range(n)]
    for i in range(n-1):
        a, b = map(int, input().split())
        tree[a-1].append(b-1)
        tree[b-1].append(a-1)
    
    ans = [0]*n
    for _ in range(q):
        p, x = map(int, input().split())
        ans[p-1] += x
    
    not_yet = deque([0])
    already = [False]*n
    already[0] = True
    
    while not_yet:
        key = not_yet.popleft()
        for value in tree[key]:
            if already[value]:
                continue
            already[value] = True
            not_yet.append(value)
            ans[value] += ans[key]
    
    print(*ans)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
n, q = map(int, input().split())
tree = {}
for i in range(n-1):
    a, b = map(int, input().split())
    tree[b] = a
ans = [0]*n
for i in range(q):
    a, b = map(int, input().split())
    ans[a-1] += b
for i in range(2, n+1):
    ans[i-1] += ans[tree[i]-1]
for i in ans:
    print(i, end=" ")

Fixed submission:
from collections import deque

def main():
    n, q = map(int, input().split())
    tree = [[] for _ in range(n)]
    for i in range(n-1):
        a, b = map(int, input().split())
        tree[a-1].append(b-1)
        tree[b-1].append(a-1)
    
    ans = [0]*n
    for _ in range(q):
        p, x = map(int, input().split())
        ans[p-1] += x
    
    not_yet = deque([0])
    already = [False]*n
    already[0] = True
    
    while not_yet:
        key = not_yet.popleft()
        for value in tree[key]:
            if already[value]:
                continue
            already[value] = True
            not_yet.append(value)
            ans[value] += ans[key]
    
    print(*ans)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
n, q = map(int, input().split())
tree = {}
for i in range(n-1):
    a, b = map(int, input().split())
    tree[b] = a
ans = [0]*n
for i in range(q):
    a, b = map(int, input().split())
    ans[a-1] += b
for i in range(2, n+1):
    ans[i-1] += ans[tree[i]-1]
print(ans)

Fixed submission:
from collections import deque

def main():
    n, q = map(int, input().split())
    tree = [[] for _ in range(n)]
    for i in range(n-1):
        a, b = map(int, input().split())
        tree[a-1].append(b-1)
        tree[b-1].append(a-1)
    
    ans = [0]*n
    for _ in range(q):
        p, x = map(int, input().split())
        ans[p-1] += x
    
    not_yet = deque([0])
    already = [False]*n
    already[0] = True
    
    while not_yet:
        key = not_yet.popleft()
        for value in tree[key]:
            if already[value]:
                continue
            already[value] = True
            not_yet.append(value)
            ans[value] += ans[key]
    
    print(*ans)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
n, q = map(int, input())
tree = {}
for i in range(n):
    a, b = map(int, input())
    tree[b] = a
ans = [0]*n
for i in range(q):
    a, b = map(int)
    ans[a-1] += b
for i in tree:
    ans[i] += ans[tree[i]]
print(ans)

Fixed submission:
from collections import deque

def main():
    n, q = map(int, input().split())
    tree = [[] for _ in range(n)]
    for i in range(n-1):
        a, b = map(int, input().split())
        tree[a-1].append(b-1)
        tree[b-1].append(a-1)
    
    ans = [0]*n
    for _ in range(q):
        p, x = map(int, input().split())
        ans[p-1] += x
    
    not_yet = deque([0])
    already = [False]*n
    already[0] = True
    
    while not_yet:
        key = not_yet.popleft()
        for value in tree[key]:
            if already[value]:
                continue
            already[value] = True
            not_yet.append(value)
            ans[value] += ans[key]
    
    print(*ans)

if __name__ == "__main__":
    main()