Buggy python submission (verdict: Time Limit Exceeded):
import sys
def input():
    return sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**7)
n,q=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n-1)]
px=[list(map(int,input().split())) for i in range(q)]

def denpan(oya,ko):
    for i in range(len(ne[ko])):
        if ne[ko][i]!=oya:
            cnt[ne[ko][i]]+=cnt[ko]
            denpan(ko,ne[ko][i])

ne=[[] for i in range(n+1)]
for i in range(n-1):
    ne[ab[i][0]].append(ab[i][1])
    ne[ab[i][1]].append(ab[i][0])
# print(ne)
cnt=[0]*(n+1)
for i in range(q):
    cnt[px[i][0]]+=px[i][1]
# print(cnt)
denpan(1,1)
cnt.remove(0)
print(' '.join(map(str,cnt)))

Fixed submission:
import sys
from collections import deque
def input():
    return sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**7)
n,q=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n-1)]
px=[list(map(int,input().split())) for i in range(q)]

# def denpan(oya,ko):
#     for i in range(len(ne[ko])):
#         if ne[ko][i]!=oya:
#             cnt[ne[ko][i]]+=cnt[ko]
#             denpan(ko,ne[ko][i])

ne=[[] for i in range(n+1)]
for i in range(n-1):
    ne[ab[i][0]].append(ab[i][1])
    ne[ab[i][1]].append(ab[i][0])
# print(ne)
cnt=[0]*(n+1)
for i in range(q):
    cnt[px[i][0]]+=px[i][1]
par=[-1]*(n+1)
stack=deque([1])
while(stack):
    v=stack.pop()
    for i in range(len(ne[v])):
        if ne[v][i]!=par[v]:
            cnt[ne[v][i]]+=cnt[v]
            par[ne[v][i]]=v
            stack.append(ne[v][i])
cnt.remove(0)
print(' '.join(map(str,cnt)))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
def input():
    return sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**7)
n,q=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n-1)]
px=[list(map(int,input().split())) for i in range(q)]

def denpan(oya,ko):
    for i in range(len(ne[ko])):
        if ne[ko][i]!=oya:
            cnt[ne[ko][i]]+=cnt[ko]
            denpan(ko,ne[ko][i])

ne=[[] for i in range(n+1)]
for i in range(n-1):
    ne[ab[i][0]].append(ab[i][1])
    ne[ab[i][1]].append(ab[i][0])
# print(ne)
cnt=[0]*(n+1)
for i in range(q):
    cnt[px[i][0]]+=px[i][1]
# print(cnt)
denpan(1,1)
for i in range(1,n+1):
    print(cnt[i])

Fixed submission:
import sys
from collections import deque
def input():
    return sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**7)
n,q=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n-1)]
px=[list(map(int,input().split())) for i in range(q)]

# def denpan(oya,ko):
#     for i in range(len(ne[ko])):
#         if ne[ko][i]!=oya:
#             cnt[ne[ko][i]]+=cnt[ko]
#             denpan(ko,ne[ko][i])

ne=[[] for i in range(n+1)]
for i in range(n-1):
    ne[ab[i][0]].append(ab[i][1])
    ne[ab[i][1]].append(ab[i][0])
# print(ne)
cnt=[0]*(n+1)
for i in range(q):
    cnt[px[i][0]]+=px[i][1]
par=[-1]*(n+1)
stack=deque([1])
while(stack):
    v=stack.pop()
    for i in range(len(ne[v])):
        if ne[v][i]!=par[v]:
            cnt[ne[v][i]]+=cnt[v]
            par[ne[v][i]]=v
            stack.append(ne[v][i])
cnt.remove(0)
print(' '.join(map(str,cnt)))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
def input():
    return sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**6)
n,q=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n-1)]
px=[list(map(int,input().split())) for i in range(q)]

def denpan(oya,ko):
    for i in range(len(ne[ko])):
        if ne[ko][i]!=oya:
            cnt[ne[ko][i]]+=cnt[ko]
            denpan(ko,ne[ko][i])

ne=[[] for i in range(n+1)]
for i in range(n-1):
    ne[ab[i][0]].append(ab[i][1])
    ne[ab[i][1]].append(ab[i][0])
# print(ne)
cnt=[0]*(n+1)
for i in range(q):
    cnt[px[i][0]]+=px[i][1]
# print(cnt)
denpan(1,1)
for i in range(1,n+1):
    print(cnt[i])

Fixed submission:
import sys
from collections import deque
def input():
    return sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**7)
n,q=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n-1)]
px=[list(map(int,input().split())) for i in range(q)]

# def denpan(oya,ko):
#     for i in range(len(ne[ko])):
#         if ne[ko][i]!=oya:
#             cnt[ne[ko][i]]+=cnt[ko]
#             denpan(ko,ne[ko][i])

ne=[[] for i in range(n+1)]
for i in range(n-1):
    ne[ab[i][0]].append(ab[i][1])
    ne[ab[i][1]].append(ab[i][0])
# print(ne)
cnt=[0]*(n+1)
for i in range(q):
    cnt[px[i][0]]+=px[i][1]
par=[-1]*(n+1)
stack=deque([1])
while(stack):
    v=stack.pop()
    for i in range(len(ne[v])):
        if ne[v][i]!=par[v]:
            cnt[ne[v][i]]+=cnt[v]
            par[ne[v][i]]=v
            stack.append(ne[v][i])
cnt.remove(0)
print(' '.join(map(str,cnt)))

Buggy python submission (verdict: Runtime Error):
n,q=map(int,input().split())
ab=[[0]*2 for i in range(n-1)]
px=[[0]*2 for i in range(q)]
for i in range(n-1):
    ab[i][0],ab[i][1]=map(int,input().split())
for i in range(q):
    px[i][0],px[i][1]=map(int,input().split())
# print(ab)
# print(px)
node=[[0] for i in range(n+1)]
for i in range(n-1):
    node[ab[i][0]].append(ab[i][1])
for i in range(q):
    node[px[i][0]][0]+=px[i][1]
# print(node)
ans=[0]*(n+1)

def flow(n):
    # print(n)
    # print(node)
    # print(ans)
    # print(len(node[n]))
    ans[n]+=node[n][0]
    for i in range(1,len(node[n])):
        node[node[n][i]][0]+=node[n][0]
        flow(node[n][i])

flow(1)
# print(ans)

ans2=ans[1:]
# print(ans2)
print(" ".join(map(str,ans2)))

Fixed submission:
import sys
from collections import deque
def input():
    return sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**7)
n,q=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n-1)]
px=[list(map(int,input().split())) for i in range(q)]

# def denpan(oya,ko):
#     for i in range(len(ne[ko])):
#         if ne[ko][i]!=oya:
#             cnt[ne[ko][i]]+=cnt[ko]
#             denpan(ko,ne[ko][i])

ne=[[] for i in range(n+1)]
for i in range(n-1):
    ne[ab[i][0]].append(ab[i][1])
    ne[ab[i][1]].append(ab[i][0])
# print(ne)
cnt=[0]*(n+1)
for i in range(q):
    cnt[px[i][0]]+=px[i][1]
par=[-1]*(n+1)
stack=deque([1])
while(stack):
    v=stack.pop()
    for i in range(len(ne[v])):
        if ne[v][i]!=par[v]:
            cnt[ne[v][i]]+=cnt[v]
            par[ne[v][i]]=v
            stack.append(ne[v][i])
cnt.remove(0)
print(' '.join(map(str,cnt)))