Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(200000)

n, q = map(int, input().split())

Adj_dict = {}
for i in range(n):
    new = {i:[]}
    Adj_dict.update(new)
for _ in range(n-1):
    a,b = map(int, input().split())
    Adj_dict[a-1].append(b-1)
    Adj_dict[b-1].append(a-1)

PX_dict = {}
for _ in range(q):
    p,x = map(int, input().split())
    if p-1 in PX_dict.keys():
        PX_dict[p-1] += x
    else:
        new = {p-1:x}
        PX_dict.update(new)

Visited = [False for _ in range(n)]
Ans = [0 for _ in range(n)]

def tree_counter(Adj=Adj_dict, PX=PX_dict, start=0, counter=0, Visited=Visited, Ans=Ans):
    
    # 終端処理
    if Visited[start] == True:
        return
    
    # Visit処理
    Visited[start] = True
    if start in PX.keys():
        counter += PX[start]
    Ans[start] = str(counter)

    for node in Adj[start]:
        if Visited[node] == False:
            tree_counter(Adj_dict, PX_dict, node, counter, Visited, Ans)
    
    return

tree_counter()
print(' '.join(Ans))

Fixed submission:
from collections import deque

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

P, X = [], []
Counter = [0 for _ in range(n)]
for _ in range(q):
    p, x = map(int, input().split())
    Counter[p-1] += x

visited = set()
visited.add(0)

dq = deque()
dq.append(0)

while dq:
    x = dq.popleft()
    for j in Adj[x]:
        if j not in visited:
            visited.add(j)
            dq.append(j)
            Counter[j] += Counter[x]
ans = ''
for i in range(n-1):
    ans += str(Counter[i]) + ' '
ans += str(Counter[n-1])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(200000)

n, q = map(int, input().split())

Adj_dict = {}
for i in range(n):
    new = {i:[]}
    Adj_dict.update(new)
for _ in range(n-1):
    a,b = map(int, input().split())
    Adj_dict[a-1].append(b-1)
    Adj_dict[b-1].append(a-1)

PX_dict = {}
for _ in range(q):
    p,x = map(int, input().split())
    if p-1 in PX_dict.keys():
        PX_dict[p-1] += x
    else:
        new = {p-1:x}
        PX_dict.update(new)

Visited = [False for _ in range(n)]
Ans = [0 for _ in range(n)]

def tree_counter(Adj=Adj_dict, PX=PX_dict, start=0, counter=0, Visited=Visited, Ans=Ans):
    
    # 終端処理
    if Visited[start] == True:
        return
    
    # Visit処理
    Visited[start] = True
    if start in PX.keys():
        counter += PX[start]
    Ans[start] = str(counter)

    for node in Adj[start]:
        if Visited[node] == False:
            tree_counter(Adj_dict, PX_dict, node, counter, Visited, Ans)
    
    return

tree_counter()
print(' '.join(Ans))

Fixed submission:
from collections import deque

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

P, X = [], []
Counter = [0 for _ in range(n)]
for _ in range(q):
    p, x = map(int, input().split())
    Counter[p-1] += x

visited = set()
visited.add(0)

dq = deque()
dq.append(0)

while dq:
    x = dq.popleft()
    for j in Adj[x]:
        if j not in visited:
            visited.add(j)
            dq.append(j)
            Counter[j] += Counter[x]
ans = ''
for i in range(n-1):
    ans += str(Counter[i]) + ' '
ans += str(Counter[n-1])
print(ans)