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

nodes = [0] * (N)
for i in range(Q):
    num, pt = list(map(int, input().split()))
    nodes[num - 1] += pt


def dfs(xs, now=0):
    print(xs, now)
    for x in xs:
        nodes[x] += now
        if childs[x] != []:
            dfs(childs[x], nodes[x])
    return


dfs(childs[0], nodes[0])
print(*nodes)

Fixed submission:
N,Q = map(int,input().split())
parents = {1:0}
for _ in range(N-1):
    a,b = map(int,input().split())
    key,val = max(a,b), min(a,b)
    parents[key] = val
counts = [0]*(N+1)
for _ in range(Q):
    p,x = map(int,input().split())
    counts[p] += x
results = [0]*(N+2)
for i in range(1,N+1):
    results[i] = counts[i]+results[parents[i]]
    print(results[i], end=' ')

Buggy python submission (verdict: Runtime Error):
# ソートが悪かったりします？
N, Q = map(int, input().split())
ab = [[0, 0]] * (N - 1)
for i in range(N - 1):
    ab[i] = list(map(int, input().split()))
# ab = sorted(ab, key=lambda x: x[0])
px = [[0, 0]] * (N - 1)
for i in range(Q):
    px[i] = list(map(int, input().split()))
# px = sorted(px, key=lambda x: x[0])
nodes = [0] * (N)
for p, x in px:
    nodes[p - 1] += x
for a, b in ab:
    nodes[b - 1] += nodes[a - 1]
print(' '.join(map(str, nodes)))


Fixed submission:
N,Q = map(int,input().split())
parents = {1:0}
for _ in range(N-1):
    a,b = map(int,input().split())
    key,val = max(a,b), min(a,b)
    parents[key] = val
counts = [0]*(N+1)
for _ in range(Q):
    p,x = map(int,input().split())
    counts[p] += x
results = [0]*(N+2)
for i in range(1,N+1):
    results[i] = counts[i]+results[parents[i]]
    print(results[i], end=' ')

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
ab = [[0, 0]] * (N - 1)
for i in range(N - 1):
    ab[i] = list(map(int, input().split()))
ab = sorted(ab, key=lambda x: x[0])
px = [[0, 0]] * (N - 1)
for i in range(Q):
    px[i] = list(map(int, input().split()))
px = sorted(px, key=lambda x: x[0])
nodes = [0] * (N)
for p, x in px:
    nodes[p - 1] += x
for a, b in ab:
    nodes[b - 1] += nodes[a - 1]
print(' '.join(map(str, nodes)))


Fixed submission:
N,Q = map(int,input().split())
parents = {1:0}
for _ in range(N-1):
    a,b = map(int,input().split())
    key,val = max(a,b), min(a,b)
    parents[key] = val
counts = [0]*(N+1)
for _ in range(Q):
    p,x = map(int,input().split())
    counts[p] += x
results = [0]*(N+2)
for i in range(1,N+1):
    results[i] = counts[i]+results[parents[i]]
    print(results[i], end=' ')

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
sons_of_root = []
edges = {}
for _ in range(N-1):
    a,b = map(int,input().split())
    if a==1:
    	sons_of_root.append(b)
    
    if a in edges.keys():
        edges[a] = edges[a]+[b]
    else:
        edges[a] = [b]
            
    if b in edges.keys():
        edges[b] = edges[b]+[a]
    else:
        edges[b] = [a]
        
counts = [0]*(N+1)
for _ in range(Q):
    p,x = map(int,input().split())
    counts[p] += x
        
queue = [sons_of_root]
cqueue = [[counts[1]]*len(sons_of_root)]
ignores = [1]
results = [0]*(N+1)
results[1] = counts[1]
while queue != []:
    vals = queue.pop(0)
    cvals = cqueue.pop(0)
    for x,c in zip(vals,cvals):
        results[x] = counts[x]+c
        sons = [val for val in edges[x] if val not in ignores]
        queue.append(sons)
        cqueue.append([results[x]]*len(sons))
        ignores.append(x)
for i in range(1,N+1):
    print(results[i], end=' ')

Fixed submission:
N,Q = map(int,input().split())
parents = {1:0}
for _ in range(N-1):
    a,b = map(int,input().split())
    key,val = max(a,b), min(a,b)
    parents[key] = val
counts = [0]*(N+1)
for _ in range(Q):
    p,x = map(int,input().split())
    counts[p] += x
results = [0]*(N+2)
for i in range(1,N+1):
    results[i] = counts[i]+results[parents[i]]
    print(results[i], end=' ')

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
sons = {1:[]}
edges = {}
for _ in range(N-1):
    a,b = map(int,input().split())
    if a==1:
    	sons[a] += [b]
    if a in edges.keys():
        edges[a] = edges[a]+[b]
    else:
        edges[a] = [b]
            
    if b in edges.keys():
        edges[b] = edges[b]+[a]
    else:
        edges[b] = [a]

counts = [0]*(N+1)
for _ in range(Q):
    p,x = map(int,input().split())
    counts[p] += x
        
stack = sons[1]
count_stack = [counts[1]]*len(stack)
ignores = set([1])
results = [0]*(N+1)
results[1] = counts[1]
next_stack = []
next_cstack = []
while stack != []:
    next_stack = []
    next_cstack = []
    for x,c in zip(stack,count_stack):
        results[x] = counts[x]+c
        sons[x] = set(edges[x])-ignores
        next_stack += sons[x]
        next_cstack += [results[x]]*len(sons[x])
        ignores = ignores | set([x])
    stack = next_stack
    count_stack = next_cstack
print(' '.join([str(results[i]) for i in range(1,N+1)]))

Fixed submission:
N,Q = map(int,input().split())
parents = {1:0}
for _ in range(N-1):
    a,b = map(int,input().split())
    key,val = max(a,b), min(a,b)
    parents[key] = val
counts = [0]*(N+1)
for _ in range(Q):
    p,x = map(int,input().split())
    counts[p] += x
results = [0]*(N+2)
for i in range(1,N+1):
    results[i] = counts[i]+results[parents[i]]
    print(results[i], end=' ')

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
sons = {1:[]}
edges = {}
for _ in range(N-1):
    a,b = map(int,input().split())
    if a==1:
    	sons[a] += [b]
    if a in edges.keys():
        edges[a] = edges[a]+[b]
    else:
        edges[a] = [b]
            
    if b in edges.keys():
        edges[b] = edges[b]+[a]
    else:
        edges[b] = [a]

counts = [0]*(N+1)
for _ in range(Q):
    p,x = map(int,input().split())
    counts[p] += x
        
stack = sons[1]
count_stack = [counts[1]]*len(stack)
ignores = set([1])
results = [0]*(N+1)
results[1] = counts[1]
next_stack = []
next_cstack = []
while stack != []:
    next_stack = []
    next_cstack = []
    for x,c in zip(stack,count_stack):
        results[x] = counts[x]+c
        sons[x] = set(edges[x])-ignores
        next_stack += sons[x]
        next_cstack += [results[x]]*len(sons[x])
        ignores = ignores | set([x])
    stack = next_stack
    count_stack = next_cstack
print(' '.join([str(results[i]) for i in range(1,N+1)]))

Fixed submission:
N,Q = map(int,input().split())
parents = {1:0}
for _ in range(N-1):
    a,b = map(int,input().split())
    key,val = max(a,b), min(a,b)
    parents[key] = val
counts = [0]*(N+1)
for _ in range(Q):
    p,x = map(int,input().split())
    counts[p] += x
results = [0]*(N+2)
for i in range(1,N+1):
    results[i] = counts[i]+results[parents[i]]
    print(results[i], end=' ')

Buggy python submission (verdict: Runtime Error):
N,Q = map(int,input().split())
sons = {1:[]}
edges = {}
for _ in range(N-1):
    a,b = map(int,input().split())
    if a==1:
    	sons[a] += [b]
    else:
        if a in edges.keys():
            edges[a] = edges[a]+[b]
        else:
            edges[a] = [b]
            
        if b in edges.keys():
            edges[b] = edges[a]+[b]
        else:
            edges[b] = [a]

counts = [0]*(N+1)
for _ in range(Q):
    p,x = map(int,input().split())
    counts[p] += x
        
stack = sons[1]
count_stack = [counts[1]]
ignores = set([])
results = [0]*(N+1)
results[1] = counts[1]
next_stack = []
next_cstack = []
while stack != []:
    next_stack = []
    next_cstack = []
    for x,c in zip(stack,count_stack):
        results[x] = counts[x]+c
        sons[x] = set(edges[x])-ignores
        next_stack += sons[x]
        next_cstack += [results[x]]*len(sons[x])
        ignores = ignores | set([x])
    stack = next_stack
    count_stack = next_cstack
print(' '.join([str(results[i]) for i in range(1,N+1)]))

Fixed submission:
N,Q = map(int,input().split())
parents = {1:0}
for _ in range(N-1):
    a,b = map(int,input().split())
    key,val = max(a,b), min(a,b)
    parents[key] = val
counts = [0]*(N+1)
for _ in range(Q):
    p,x = map(int,input().split())
    counts[p] += x
results = [0]*(N+2)
for i in range(1,N+1):
    results[i] = counts[i]+results[parents[i]]
    print(results[i], end=' ')

Buggy python submission (verdict: Runtime Error):
N,Q = map(int,input().split())
sons = {1:[]}
edges = {}
for _ in range(N-1):
    a,b = map(int,input().split())
    if a==1:
    	sons[a] += [b]
    else:
      	edges[a] = edges[a]+[b] if b in edges.keys() else [b]
        edgese[b] = edges[b]+[a] if a in edges.keys() else [a]

counts = [0]*(N+1)
for _ in range(Q):
    p,x = map(int,input().split())
    counts[p] += x
        
stack = sons[1]
count_stack = [counts[1]]
ignores = set([])
results = [0]*(N+1)
results[1] = counts[1]
while stack != []:
  	next_stack = []
    next_cstack = []
	for x,c in zip(stack,count_stack):
      	results[x] = counts[x]+c
  		sons[x] = set(edges[x])-ignores
    	next_stack += sons[x]
        next_cstack += [results[x]]*len(sons[x])
        ignores = ignores | set([x])
        print(results[i], end=' ')
    stack = next_stack
    count_stack = next_cstack

Fixed submission:
N,Q = map(int,input().split())
parents = {1:0}
for _ in range(N-1):
    a,b = map(int,input().split())
    key,val = max(a,b), min(a,b)
    parents[key] = val
counts = [0]*(N+1)
for _ in range(Q):
    p,x = map(int,input().split())
    counts[p] += x
results = [0]*(N+2)
for i in range(1,N+1):
    results[i] = counts[i]+results[parents[i]]
    print(results[i], end=' ')

Buggy python submission (verdict: Runtime Error):
N,Q = map(int,input().split())
parents = {1:0}
for _ in range(N-1):
    a,b = map(int,input().split())
    key,val = max(a,b), min(a,b)
    parents[key] = val
counts = [0]*(N+1)
for _ in range(Q):
    p,x = map(int,input().split())
    counts[p] += x
results = [0]*(N+2)
for i in range(1,N+1):
    results[i] = counts[i]+results[parents[i]]
    print(results[i], end=' ')

Fixed submission:
N,Q = map(int,input().split())
parents = {1:0}
for _ in range(N-1):
    a,b = map(int,input().split())
    key,val = max(a,b), min(a,b)
    parents[key] = val
counts = [0]*(N+1)
for _ in range(Q):
    p,x = map(int,input().split())
    counts[p] += x
results = [0]*(N+2)
for i in range(1,N+1):
    results[i] = counts[i]+results[parents[i]]
    print(results[i], end=' ')