Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
edge = [[] for _ in range(N)]
for i in range(N-1):
    a,b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

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

import sys
sys.setrecursionlimit(10**8)
def dfs(v):
    if len(edge[v])==0:
        return
    for u in edge[v]:
        if visited[u]==False:
            ans[u] += ans[v]
            visited[u]=True
            dfs(u)
    return

visited = [False]*N
visited[0]= True
dfs(0)
print(*ans, sep=' ')

Fixed submission:
N, Q = map(int, input().split())
edge = [[] for _ in range(N)]
for i in range(N-1):
    a,b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

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

from collections import deque

visited = [False]*N
d = deque([0])
while len(d)>0:
    v = d.popleft()
    visited[v]= True
    for u in edge[v]:
        if visited[u]==False:
            ans[u] += ans[v]
            visited[u]=True
            d.append(u)

print(*ans, sep=' ')

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
tree = [[] for _ in range(N+1)]
for i in range(N-1):
  a,b = map(int, input().split())
  tree[a].append(b)

counter = [0]*(N+1)
def dfs(p,x):
  counter[p] += x
  if len(tree[p])==0:
    return None
  for q in tree[p]:
    dfs(q,x)
  return None

for i in range(Q):
  p,x = map(int, input().split())
  dfs(p,x)
  
for i in range(1,N+1):
  print(counter[i],end=' ')

Fixed submission:
N, Q = map(int, input().split())
edge = [[] for _ in range(N)]
for i in range(N-1):
    a,b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

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

from collections import deque

visited = [False]*N
d = deque([0])
while len(d)>0:
    v = d.popleft()
    visited[v]= True
    for u in edge[v]:
        if visited[u]==False:
            ans[u] += ans[v]
            visited[u]=True
            d.append(u)

print(*ans, sep=' ')

Buggy python submission (verdict: Runtime Error):
N, Q  = map(int, input().split())
tree = [0]*(N+1)
counts = [0]*(N+1)
pluses = [0]*(N+1)
for i in range(1,N):
  tree[i] = []
  a,b = map(int, input().split())
  tree[a].append(b)
tree[N] = []

i = N
while i>0:
  pluses[i] = [i]
  if len(tree[i])!=0:
    for p in tree[i]:
      for q in pluses[p]:
        pluses[i].append(q)
  i -= 1
#print(pluses)

for i in range(Q):
  p,x = map(int, input().split())
  for q in pluses[p]:
    counts[q]+=x
#print(tree)
for i in range(1,N+1):
  print(counts[i],end=' ')

  

Fixed submission:
N, Q = map(int, input().split())
edge = [[] for _ in range(N)]
for i in range(N-1):
    a,b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

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

from collections import deque

visited = [False]*N
d = deque([0])
while len(d)>0:
    v = d.popleft()
    visited[v]= True
    for u in edge[v]:
        if visited[u]==False:
            ans[u] += ans[v]
            visited[u]=True
            d.append(u)

print(*ans, sep=' ')

Buggy python submission (verdict: Runtime Error):
N, Q  = map(int, input().split())
tree = [0]*(N+1)
counts = [0]*(N+1)
for i in range(1,N):
  tree[i] = []
  a,b = map(int, input().split())
  tree[a].append(b)
tree[N] = []

def plus(p,x):
  #print(p,x,counts)
  counts[p] += x
  if len(tree[p])==0:
  	pass
  else:
    #print(tree[p][-1],x)
    for q in tree[p]:
      plus(q,x)

for i in range(Q):
  p,x = map(int, input().split())
  plus(p,x)
#print(tree)
for i in range(1,N+1):
  print(counts[i],end=' ')

  

Fixed submission:
N, Q = map(int, input().split())
edge = [[] for _ in range(N)]
for i in range(N-1):
    a,b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

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

from collections import deque

visited = [False]*N
d = deque([0])
while len(d)>0:
    v = d.popleft()
    visited[v]= True
    for u in edge[v]:
        if visited[u]==False:
            ans[u] += ans[v]
            visited[u]=True
            d.append(u)

print(*ans, sep=' ')