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

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

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

ans=[0]*n

check=[False]*n
temp=0
def dfs(v):
    global temp

    check[v]=True
    temp+=add[v]
    ans[v]=temp

    for next in G[v]:
        if check[next]:
            continue
        dfs(next)
    
    temp-=add[v]

dfs(0)

print(*ans)



Fixed submission:
from collections import deque

N,Q=map(int,input().split())
L=[[] for _ in range(N+1)]
for i in range(N-1):
    a,b=map(int,input().split())
    L[a].append(b)
    L[b].append(a)
count=[0]*(N+1)
for j in range(Q):
    p,x=map(int,input().split())
    count[p]+=x

#print(count)

q=deque() #queueとして(popleftとappend)
q.append(1)
parent=[-1]*(N+1)
#parent[1]=1

while q:
    now=q.popleft()
    for k in L[now]:
        if parent[now]==k:
            continue
        count[k]+=count[now]
        parent[k]=now
        q.append(k)
        #print(parent)

print(*count[1:])

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

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

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

ans=[0]*n

check=[False]*n
temp=0
def dfs(v):
    global temp

    check[v]=True
    temp+=add[v]
    ans[v]=temp

    for next in G[v]:
        if check[next]:
            continue
        dfs(next)
    
    temp-=add[v]

dfs(0)

print(*ans)



Fixed submission:
from collections import deque

N,Q=map(int,input().split())
L=[[] for _ in range(N+1)]
for i in range(N-1):
    a,b=map(int,input().split())
    L[a].append(b)
    L[b].append(a)
count=[0]*(N+1)
for j in range(Q):
    p,x=map(int,input().split())
    count[p]+=x

#print(count)

q=deque() #queueとして(popleftとappend)
q.append(1)
parent=[-1]*(N+1)
#parent[1]=1

while q:
    now=q.popleft()
    for k in L[now]:
        if parent[now]==k:
            continue
        count[k]+=count[now]
        parent[k]=now
        q.append(k)
        #print(parent)

print(*count[1:])

Buggy python submission (verdict: Runtime Error):
n,q=map(int,input().split())
G=[[] for i in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

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

ans=[0]*n

check=[False]*n
temp=0
def dfs(v):
    global temp

    check[v]=True
    temp+=add[v]
    ans[v]=temp

    for next in G[v]:
        if check[next]:
            continue
        dfs(next)
    
    temp-=add[v]

dfs(0)

print(*ans)



Fixed submission:
from collections import deque

N,Q=map(int,input().split())
L=[[] for _ in range(N+1)]
for i in range(N-1):
    a,b=map(int,input().split())
    L[a].append(b)
    L[b].append(a)
count=[0]*(N+1)
for j in range(Q):
    p,x=map(int,input().split())
    count[p]+=x

#print(count)

q=deque() #queueとして(popleftとappend)
q.append(1)
parent=[-1]*(N+1)
#parent[1]=1

while q:
    now=q.popleft()
    for k in L[now]:
        if parent[now]==k:
            continue
        count[k]+=count[now]
        parent[k]=now
        q.append(k)
        #print(parent)

print(*count[1:])