Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N, Q = map(int, input().split())
child = [[i] for i in range(N)]
counter = [0] * N
graph = [deque([]) for _ in range(N + 1)]
for i in range(N - 1):
  a, b =  map(int, input().split())
  graph[a - 1].append(b - 1)
  graph[b - 1].append(a - 1)
  
for i in range(Q):
  p, x = map(int, input().split())
  counter[p - 1] += x 

#print(graph, counter)
# 深さ優先探索
def dfs(v):
    #global time
    #time += 1
    visited[v] = 1
    stack = [v]
    #print(stack, v)
    #arrive_time[v] = time
    while stack:
        v = stack[-1]
        if graph[v]:
            w = graph[v].popleft()
            if visited[w] == 0:
              visited[w] = 1
              counter[w] += counter[v]
              stack.append(w) 
        else:
            stack.pop()          
    return 0

visited = [0] * N
# 孤立している頂点対策
for i in range(N):
    if visited[i] == 0:
       dfs(i)


#print(counter)
for i in range(N):
  print(counter[i], end = " ")

Fixed submission:
import sys
input = sys.stdin.readline


N,Q=map(int,input().split())
EDGE=[list(map(int,input().split())) for i in range(N-1)]
PLUS=[list(map(int,input().split())) for i in range(Q)]

SCORE=[0]*(N+1)
for p,x in PLUS:
    SCORE[p]+=x

ELIST=[[] for i in range(N+1)]

for x,y in EDGE:
    ELIST[x].append(y)
    ELIST[y].append(x)
#print(ELIST)

from collections import deque
Q=deque([1])

USED=[0]*(N+1)
USED[1]=1
#USED = [0, 1, 0, 0, 0] Ex1
#SCORE = [0, 100, 10, 1, 0] Ex1
#ELIST = [[], [2], [1, 3, 4], [2], [2]] Ex1

while Q:
    x=Q.pop()

    for to in ELIST[x]:
        if USED[to]==0:
            USED[to]=1
            SCORE[to]+=SCORE[x]
            Q.append(to)

print(*SCORE[1:])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N, Q = map(int, input().split())
child = [[i] for i in range(N)]
counter = [0] * N
graph = [deque([]) for _ in range(N + 1)]
for i in range(N - 1):
  a, b =  map(int, input().split())
  graph[a - 1].append(b - 1)
  graph[b - 1].append(a - 1)
  
for i in range(Q):
  p, x = map(int, input().split())
  counter[p - 1] += x 

#print(graph, counter)
# 深さ優先探索
def dfs(v):
    #global time
    #time += 1
    visited[v] = 1
    stack = [v]
    #print(stack, v)
    #arrive_time[v] = time
    while stack:
        v = stack[-1]
        if graph[v]:
            w = graph[v].popleft()
            if visited[w] == 0:
              visited[w] = 1
              counter[w] += counter[v]
              stack.append(w) 
        else:
            stack.pop()          
    return 0

visited = [0] * N
# 孤立している頂点対策
for i in range(N):
    if visited[i] == 0:
       dfs(i)


#print(counter)
for i in range(N):
  print(counter[i], end = " ")

Fixed submission:
import sys
input = sys.stdin.readline


N,Q=map(int,input().split())
EDGE=[list(map(int,input().split())) for i in range(N-1)]
PLUS=[list(map(int,input().split())) for i in range(Q)]

SCORE=[0]*(N+1)
for p,x in PLUS:
    SCORE[p]+=x

ELIST=[[] for i in range(N+1)]

for x,y in EDGE:
    ELIST[x].append(y)
    ELIST[y].append(x)
#print(ELIST)

from collections import deque
Q=deque([1])

USED=[0]*(N+1)
USED[1]=1
#USED = [0, 1, 0, 0, 0] Ex1
#SCORE = [0, 100, 10, 1, 0] Ex1
#ELIST = [[], [2], [1, 3, 4], [2], [2]] Ex1

while Q:
    x=Q.pop()

    for to in ELIST[x]:
        if USED[to]==0:
            USED[to]=1
            SCORE[to]+=SCORE[x]
            Q.append(to)

print(*SCORE[1:])