Buggy python submission (verdict: Time Limit Exceeded):
import queue

N,Q = map(int,input().split())
Ki_p = [0 for i in range(N+1)]
Ki_c = [[] for i in range(N+1)]
Ki_co = [0 for i in range(N+1)]
 
for i in range(N-1):
    a,b = map(int,input().split())
    Ki_p[b] = a
    Ki_c[a] += [b]
 
for i in range(Q):
    p,x = map(int,input().split())
    Ki_co[p] += x
 
ans = [0 for i in range(N+1)]
q = queue.Queue()
q.put(1)
while not q.empty():
    vi = q.get()
    ans[vi] = Ki_co[vi] + ans[Ki_p[vi]]
    for a in Ki_c[vi]:
        q.put(a)
 
print(' '.join(map(str,ans[1:N+1])))

Fixed submission:
N,Q = map(int,input().split())
Ki_p = [0 for i in range(N+1)]
Ki_c = [[] for i in range(N+1)]
Ki_co = [0 for i in range(N+1)]
 
for i in range(N-1):
    a,b = map(int,input().split())
    Ki_p[b] = a
    Ki_c[a] += [b]
 
for i in range(Q):
    p,x = map(int,input().split())
    Ki_co[p] += x
 
ans = [0 for i in range(N+1)]
q = {1}
for i in range(N):
    vi = q.pop()
    ans[vi] = Ki_co[vi] + ans[Ki_p[vi]]
    q |= set(Ki_c[vi])
    
print(' '.join(map(str,ans[1:N+1])))

Buggy python submission (verdict: Runtime Error):
N,Q = map(int,input().split())
Ki_p = [0 for i in range(N+1)]
Ki_c = [[] for i in range(N+1)]
Ki_co = [0 for i in range(N+1)]

def answer(vi,ans):
    ans[vi] = Ki_co[vi] + ans[Ki_p[vi]]
    for v in Ki_c[vi]:
        answer(v,ans)    

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

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

ans = [0 for i in range(N+1)]
answer(1,ans)

print(' '.join(map(str,ans[1:N+1])))

Fixed submission:
N,Q = map(int,input().split())
Ki_p = [0 for i in range(N+1)]
Ki_c = [[] for i in range(N+1)]
Ki_co = [0 for i in range(N+1)]
 
for i in range(N-1):
    a,b = map(int,input().split())
    Ki_p[b] = a
    Ki_c[a] += [b]
 
for i in range(Q):
    p,x = map(int,input().split())
    Ki_co[p] += x
 
ans = [0 for i in range(N+1)]
q = {1}
for i in range(N):
    vi = q.pop()
    ans[vi] = Ki_co[vi] + ans[Ki_p[vi]]
    q |= set(Ki_c[vi])
    
print(' '.join(map(str,ans[1:N+1])))

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
Ki_p = [0 for i in range(N+1)]
Ki_c = [[] for i in range(N+1)]
Ki_co = [0 for i in range(N+1)]

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

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

ans = [0 for i in range(N+1)]
vc = [1]
for i in range(N):
    vi = vc.pop(0)
    ans[vi] = Ki_co[vi] + ans[Ki_p[vi]]
    vc += Ki_c[vi]

print(' '.join(map(str,ans[1:N+1])))

Fixed submission:
N,Q = map(int,input().split())
Ki_p = [0 for i in range(N+1)]
Ki_c = [[] for i in range(N+1)]
Ki_co = [0 for i in range(N+1)]
 
for i in range(N-1):
    a,b = map(int,input().split())
    Ki_p[b] = a
    Ki_c[a] += [b]
 
for i in range(Q):
    p,x = map(int,input().split())
    Ki_co[p] += x
 
ans = [0 for i in range(N+1)]
q = {1}
for i in range(N):
    vi = q.pop()
    ans[vi] = Ki_co[vi] + ans[Ki_p[vi]]
    q |= set(Ki_c[vi])
    
print(' '.join(map(str,ans[1:N+1])))

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
Ki_p = [0 for i in range(N+1)]
Ki_c = [[] for i in range(N+1)]
Ki_co = [0 for i in range(N+1)]
v = set([1])
re = []

for i in range(N-1):
    a,b = map(int,input().split())
    if a in v:
        Ki_p[b] = a
        Ki_c[a] += [b]
        v.add(b)
    elif b in v:
        Ki_p[a] = b
        Ki_c[b] += [a]
        v.add(a)
    else:  re.append([a,b])

while len(re) > 0:
    for i in range(len(re)):
        a,b = (x for x in re.pop(0))
        if a in v:
            Ki_p[b] = a
            Ki_c[a] += [b]
            v.add(b)
        elif b in v:
            Ki_p[a] = b
            Ki_c[b] += [a]
            v.add(a)
        else:  re.append([a,b])

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

ans = [0 for i in range(N+1)]
vc = [1]
for i in range(N):
    vi = vc.pop(0)
    ans[vi] = Ki_co[vi] + ans[Ki_p[vi]]
    vc += Ki_c[vi]

print(' '.join(map(str,ans[1:N+1])))

Fixed submission:
N,Q = map(int,input().split())
Ki_p = [0 for i in range(N+1)]
Ki_c = [[] for i in range(N+1)]
Ki_co = [0 for i in range(N+1)]
 
for i in range(N-1):
    a,b = map(int,input().split())
    Ki_p[b] = a
    Ki_c[a] += [b]
 
for i in range(Q):
    p,x = map(int,input().split())
    Ki_co[p] += x
 
ans = [0 for i in range(N+1)]
q = {1}
for i in range(N):
    vi = q.pop()
    ans[vi] = Ki_co[vi] + ans[Ki_p[vi]]
    q |= set(Ki_c[vi])
    
print(' '.join(map(str,ans[1:N+1])))