Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

def dfs(v, p=-1):
    for u in to[v]:
        if u == p: continue
        ans[u] += ans[v]
        dfs(u, v)
    
def main():
    for i in range(N-1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        to[a].append(b)
        to[b].append(a)
        
    for i in range(Q):
        p, x = map(int, input().split())
        ans[p-1] += x
        
    dfs(0)
    
    for a in ans: print(a)

if __name__ == '__main__':
    N, Q = map(int, input().split())
    to = [[] for i in range(200005)]
    ans = [0] * N
    
    main()

Fixed submission:
from collections import deque

def main():
  N, Q = map(int, input().split())
  visited = [False] * (N+1)
  graph = {i:deque() for i in range(N+1)}

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

  visited[1] = True

  c = [0] * (N+1)
  for i in range(Q):
    p, x = map(int, input().split())
    c[p] += x
    
  q = [1]
  while q:
    per = q.pop()
    for child in graph[per]:
      if not visited[child]:
        visited[child] = True
        c[child] += c[per]
        q.append(child)

  for i in range(1, N+1):
    print(c[i], '', end='')

if __name__ == '__main__':
  main()

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

def dfs(v, p=-1):
    for u in to[v]:
        if u == p: continue
        ans[u] += ans[v]
        dfs(u, v)
    
def main():
    for i in range(N-1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        to[a].append(b)
        to[b].append(a)
        
    for i in range(Q):
        p, x = map(int, input().split())
        ans[p-1] += x
        
    dfs(0)
    
    for a in ans: print(a)

if __name__ == '__main__':
    N, Q = map(int, input().split())
    to = [[] for i in range(N)]
    ans = [0] * N
    
    main()

Fixed submission:
from collections import deque

def main():
  N, Q = map(int, input().split())
  visited = [False] * (N+1)
  graph = {i:deque() for i in range(N+1)}

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

  visited[1] = True

  c = [0] * (N+1)
  for i in range(Q):
    p, x = map(int, input().split())
    c[p] += x
    
  q = [1]
  while q:
    per = q.pop()
    for child in graph[per]:
      if not visited[child]:
        visited[child] = True
        c[child] += c[per]
        q.append(child)

  for i in range(1, N+1):
    print(c[i], '', end='')

if __name__ == '__main__':
  main()

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

def dfs(v, p=-1):
    for u in to[v]:
        if u == p: continue
        ans[u] += ans[v]
        dfs(u, v)
    
def main():
    for i in range(N-1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        to[a].append(b)
        to[b].append(a)
        
    for i in range(Q):
        p, x = map(int, input().split())
        ans[p-1] += x
        
    dfs(0)
    
    print(' '.join(map(str, ans)))

if __name__ == '__main__':
    N, Q = map(int, input().split())
    to = [[] for i in range(N)]
    ans = [0] * N
    
    main()

Fixed submission:
from collections import deque

def main():
  N, Q = map(int, input().split())
  visited = [False] * (N+1)
  graph = {i:deque() for i in range(N+1)}

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

  visited[1] = True

  c = [0] * (N+1)
  for i in range(Q):
    p, x = map(int, input().split())
    c[p] += x
    
  q = [1]
  while q:
    per = q.pop()
    for child in graph[per]:
      if not visited[child]:
        visited[child] = True
        c[child] += c[per]
        q.append(child)

  for i in range(1, N+1):
    print(c[i], '', end='')

if __name__ == '__main__':
  main()

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
child_per = {1:0}
for i in range(N-1):
  a, b = map(int, input().split())
  child_per[b] = a
  
c = [0] * (N+1)
for i in range(Q):
  p, x = map(int, input().split())
  c[p] += x

for i in range(1, N+1):
  c[i] += c[child_per[i]]
  print(c[i], '', end='')

Fixed submission:
from collections import deque

def main():
  N, Q = map(int, input().split())
  visited = [False] * (N+1)
  graph = {i:deque() for i in range(N+1)}

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

  visited[1] = True

  c = [0] * (N+1)
  for i in range(Q):
    p, x = map(int, input().split())
    c[p] += x
    
  q = [1]
  while q:
    per = q.pop()
    for child in graph[per]:
      if not visited[child]:
        visited[child] = True
        c[child] += c[per]
        q.append(child)

  for i in range(1, N+1):
    print(c[i], '', end='')

if __name__ == '__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N, Q = map(int, input().split())
ans = np.zeros((N+1), dtype=np.int)
graph = {i:[None, []] for i in range(1, N+1)}
nums = [False] * (N)
visited = [False] * (N+1)

for i in range(N-1):
    a, b = map(int, input().split())
    graph[b][0] = a
    graph[a][1].append(b)
    nums[a] = True
        
q = [idx+1 for idx, _ in enumerate(nums) if not _]

while q:
    n = q.pop(0)
    visited[n] = True

    par, child = graph[n]
    if not par is None and not visited[par]:
        graph[par][1].extend(child)
        q.append(par)
        
for i in range(Q):
    p, x = map(int, input().split())
    ans[p] += x
    
for i in range(1, N+1):
    ans[graph[i][1]] += ans[i]
    print(ans[i])

Fixed submission:
from collections import deque

def main():
  N, Q = map(int, input().split())
  visited = [False] * (N+1)
  graph = {i:deque() for i in range(N+1)}

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

  visited[1] = True

  c = [0] * (N+1)
  for i in range(Q):
    p, x = map(int, input().split())
    c[p] += x
    
  q = [1]
  while q:
    per = q.pop()
    for child in graph[per]:
      if not visited[child]:
        visited[child] = True
        c[child] += c[per]
        q.append(child)

  for i in range(1, N+1):
    print(c[i], '', end='')

if __name__ == '__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N, Q = map(int, input().split())
ans = np.zeros((N+1), dtype=np.int)
graph = {i:[None, []] for i in range(1, N+1)}
nums = [False] * (N)
visited = [False] * (N+1)

for i in range(N-1):
    a, b = map(int, input().split())
    graph[b][0] = a
    graph[a][1].append(b)
    nums[a-1] = True
        
q = [idx+1 for idx, _ in enumerate(nums) if not _]

while q:
    n = q.pop(0)
    visited[n] = True

    par, child = graph[n]
    if not par is None and not visited[par]:
        graph[par][1].extend(child)
        q.append(par)
        
for i in range(Q):
    p, x = map(int, input().split())
    ans[p] += x
    ans[graph[p][1]] += x
    
for n in ans[1:]:
    print(n, '', end='')

Fixed submission:
from collections import deque

def main():
  N, Q = map(int, input().split())
  visited = [False] * (N+1)
  graph = {i:deque() for i in range(N+1)}

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

  visited[1] = True

  c = [0] * (N+1)
  for i in range(Q):
    p, x = map(int, input().split())
    c[p] += x
    
  q = [1]
  while q:
    per = q.pop()
    for child in graph[per]:
      if not visited[child]:
        visited[child] = True
        c[child] += c[per]
        q.append(child)

  for i in range(1, N+1):
    print(c[i], '', end='')

if __name__ == '__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
import numpy as np

N, Q = map(int, input().split())
ans = np.zeros((N+1), dtype=np.int)
graph = {i:[None, []] for i in range(1, N+1)}
nums = {i for i in range(1, N+1)}
visited = [False] * (N+1)

for i in range(N-1):
    a, b = map(int, input().split())
    graph[b][0] = a
    graph[a][1].append(b)
    if a in nums:
        nums.remove(a)

q = [(0, n) for n in nums]

while q:
    x, n = heapq.heappop(q)
    
    if not visited[n]:
        visited[n] = True
        par, child = graph[n]
        
        if not par is None:
            graph[par][1].extend(child)
        
            heapq.heappush(q, (x+1, par))
for i in range(Q):
    p, x = map(int, input().split())
    ans[p] += x
    ans[graph[p][1]] += x
    
for n in ans[1:]:
    print(n, '', end='')


Fixed submission:
from collections import deque

def main():
  N, Q = map(int, input().split())
  visited = [False] * (N+1)
  graph = {i:deque() for i in range(N+1)}

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

  visited[1] = True

  c = [0] * (N+1)
  for i in range(Q):
    p, x = map(int, input().split())
    c[p] += x
    
  q = [1]
  while q:
    per = q.pop()
    for child in graph[per]:
      if not visited[child]:
        visited[child] = True
        c[child] += c[per]
        q.append(child)

  for i in range(1, N+1):
    print(c[i], '', end='')

if __name__ == '__main__':
  main()