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

def dfs(number_list, memo_number):
    for number in number_list:
        if number in check_list:
            continue
        point = ans[memo_number]
        check_list.append(number)

        ans[number] += point
        dfs(graph[number], number)
    

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

graph = [[] for _ in range(n+10)]
for a,b in li_ab:
    graph[a].append(b)
    graph[b].append(a)

ans = [0 for _ in range(n+1)]
for p,x in li_px:
    ans[p] += x

check_list = [1]
point = 0
dfs(graph[1], 1)
    
print(*ans[1:])


Fixed submission:
n, q = map(int, input().split())
li_nq = [list(map(int, input().split())) for _ in range(n-1)]
li_px = [list(map(int, input().split())) for _ in range((q))]

graph = [[] for _ in range(n+1)]
for i, j in li_nq:
    graph[i].append(j)
    graph[j].append(i)

ans = [0 for _ in range(n+1)]
for i, j in li_px:
    ans[i] += j

check_list = [None] * (n+1)
stack = [1]

while stack:
    num = stack.pop()
    for i in graph[num]:
        if check_list[num] == i:
            continue
        stack.append(i)
        ans[i] += ans[num]
        check_list[i] = num

print(*ans[1:])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())

tyouten = [list(map(int,input().split())) for _ in range(n-1)]
tree = [list(map(int,input().split())) for _ in range(q)]
ans = [0] * n
temp = [[] for i in range(1,n+1)]
temp2 = [[0] for _ in range(n)]

tyouten.sort()

for i in range(n-1):
    temp[tyouten[i][0]-1].append(tyouten[i][1])

for i in range(q):
    temp2[tree[i][0]-1][0] += tree[i][1]
    
for i in range(n):
    ans[i] += temp2[i][0]
    for j in temp[i]:
        ans[j-1] += ans[i]
    
print(*ans)


Fixed submission:
n, q = map(int, input().split())
li_nq = [list(map(int, input().split())) for _ in range(n-1)]
li_px = [list(map(int, input().split())) for _ in range((q))]

graph = [[] for _ in range(n+1)]
for i, j in li_nq:
    graph[i].append(j)
    graph[j].append(i)

ans = [0 for _ in range(n+1)]
for i, j in li_px:
    ans[i] += j

check_list = [None] * (n+1)
stack = [1]

while stack:
    num = stack.pop()
    for i in graph[num]:
        if check_list[num] == i:
            continue
        stack.append(i)
        ans[i] += ans[num]
        check_list[i] = num

print(*ans[1:])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())

tyouten = [list(map(int,input().split())) for _ in range(n-1)]
tree = [list(map(int,input().split())) for _ in range(q)]
ans = [0] * n
temp = [] * n
for i in range(n):
    temp.append([i+1])
temp[0] = [x for x in range(1,n+1)]    

tyouten.sort()

for i in range(n-1):
    if i == 0:
        continue
    temp[tyouten[i][0]-1].append(tyouten[i][1])


for i in range(q):
    s = tree[i][0] - 1
    t = tree[i][1]
    if s == 0:
        for i in range(n):
            ans[i] += t
    else:
        for i in temp[s]:
            ans[i-1] += t

print(*ans)

Fixed submission:
n, q = map(int, input().split())
li_nq = [list(map(int, input().split())) for _ in range(n-1)]
li_px = [list(map(int, input().split())) for _ in range((q))]

graph = [[] for _ in range(n+1)]
for i, j in li_nq:
    graph[i].append(j)
    graph[j].append(i)

ans = [0 for _ in range(n+1)]
for i, j in li_px:
    ans[i] += j

check_list = [None] * (n+1)
stack = [1]

while stack:
    num = stack.pop()
    for i in graph[num]:
        if check_list[num] == i:
            continue
        stack.append(i)
        ans[i] += ans[num]
        check_list[i] = num

print(*ans[1:])