Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
ab_lst = [list(map(int, input().split())) for _ in range(n-1)]
px_lst = [list(map(int, input().split())) for _ in range(q)]


neighbor = [[] for _ in range(n+1)]
for edge in ab_lst:
    neighbor[edge[0]].append(edge[1])

root_value = [0] * (n+1)
for px in px_lst:
    root_value[px[0]] += px[1]

res = [0] * (n+1)
queue = [(1, root_value[1])]
while len(queue) > 0:
    pair = queue.pop()
    res[pair[0]] += pair[1]
    if neighbor[pair[0]] != []:
        for i in neighbor[pair[0]]:
            queue.append((i, pair[1] + root_value[i]))
    
for i in res[1:]:
    print(i, end=" ")

Fixed submission:
n, q = map(int, input().split())

neighbor = [[] for _ in range(n+1)]
for i in range(n-1):
    a, b = map(int, input().split())
    neighbor[a].append(b)

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

res = [0] * (n+1)
queue = [(1, root_value[1])]
while len(queue) > 0:
    pair = queue.pop()
    res[pair[0]] += pair[1]
    if neighbor[pair[0]] != []:
        for i in neighbor[pair[0]]:
            queue.append((i, pair[1] + root_value[i]))
    
for i in res[1:]:
    print(i, end=" ")

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**7)

n, q = map(int, input().split())
ab_lst = [list(map(int, input().split())) for _ in range(n-1)]
px_lst = [list(map(int, input().split())) for _ in range(q)]

res = [0] * (n+1)
neighbor = [[] for _ in range(n+1)]
for edge in ab_lst:
    neighbor[edge[0]].append(edge[1])

root_value = [0] * (n+1)
for px in px_lst:
    root_value[px[0]] += px[1]
    
def dfs(root, value):
    res[root] += value
    if neighbor[root] != []:
        for i in neighbor[root]:
            dfs(i, value + root_value[i])

dfs(1, root_value[1])
            
for i in res[1:]:
    print(i, end=" ")

Fixed submission:
n, q = map(int, input().split())

neighbor = [[] for _ in range(n+1)]
for i in range(n-1):
    a, b = map(int, input().split())
    neighbor[a].append(b)

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

res = [0] * (n+1)
queue = [(1, root_value[1])]
while len(queue) > 0:
    pair = queue.pop()
    res[pair[0]] += pair[1]
    if neighbor[pair[0]] != []:
        for i in neighbor[pair[0]]:
            queue.append((i, pair[1] + root_value[i]))
    
for i in res[1:]:
    print(i, end=" ")

Buggy python submission (verdict: Runtime Error):
n, q = map(int, input().split())
ab_lst = [list(map(int, input().split())) for _ in range(n-1)]
px_lst = [list(map(int, input().split())) for _ in range(q)]

res = [0] * (n+1)
neighbor = [[] for _ in range(n+1)]
for edge in ab_lst:
    neighbor[edge[0]].append(edge[1])

def counter_add(root, v):
    res[root] += v
    if neighbor[root] != []:
        for i in neighbor[root]:
            counter_add(i, v)

for px in px_lst:
    counter_add(px[0], px[1])
    
for i in res[1:]:
    print(i, end=" ")

Fixed submission:
n, q = map(int, input().split())

neighbor = [[] for _ in range(n+1)]
for i in range(n-1):
    a, b = map(int, input().split())
    neighbor[a].append(b)

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

res = [0] * (n+1)
queue = [(1, root_value[1])]
while len(queue) > 0:
    pair = queue.pop()
    res[pair[0]] += pair[1]
    if neighbor[pair[0]] != []:
        for i in neighbor[pair[0]]:
            queue.append((i, pair[1] + root_value[i]))
    
for i in res[1:]:
    print(i, end=" ")

Buggy python submission (verdict: Runtime Error):
n, q = map(int, input().split())
ab_lst = [list(map(int, input().split())) for _ in range(n-1)]
px_lst = [list(map(int, input().split())) for _ in range(q)]

res = [0] * (n+1)
neighbor = [[] for _ in range(n+1)]
for edge in ab_lst:
    neighbor[edge[0]].append(edge[1])

def counter_add(root, v):
    res[root] += v
    if neighbor[root] != []:
        for i in neighbor[root]:
            counter_add(i, v)

for px in px_lst:
    counter_add(px[0], px[1])
print(res)

Fixed submission:
n, q = map(int, input().split())

neighbor = [[] for _ in range(n+1)]
for i in range(n-1):
    a, b = map(int, input().split())
    neighbor[a].append(b)

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

res = [0] * (n+1)
queue = [(1, root_value[1])]
while len(queue) > 0:
    pair = queue.pop()
    res[pair[0]] += pair[1]
    if neighbor[pair[0]] != []:
        for i in neighbor[pair[0]]:
            queue.append((i, pair[1] + root_value[i]))
    
for i in res[1:]:
    print(i, end=" ")