Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int,input().split())
l = [list(map(int,input().split())) for _ in range(N-1)]
m = [list(map(int,input().split())) for _ in range(Q)]
ll = [0]*N
ans = [0]*N
bb = [[i] for i in range(1,N+1)]
for i in l:
    bb[i[0]-1].append(i[1])
for i in m:
    ll[i[0]-1] += int(i[1])

# print("bb=",bb)
# print("ll=",ll)
for i in range(N):
    for k in range(len(bb[i])):
        if k == 0 :
            ans[i] += ll[i]
        else:
            ll[bb[i][k]-1] += ll[i]
print(*ans)

Fixed submission:
n, q = map(int, input().split())
ki = [0] * (n + 1)
for i in range(n - 1):
    a, b = map(int, input().split())
    ki[b] = a
# print("ki=",ki)

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

for i in range(1, n + 1):
    c[i] += c[ki[i]]
# print(c)

print(" ".join(map(str, c[1:])))

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int,input().split())
l = [list(map(int,input().split())) for _ in range(N-1)]
m = [list(map(int,input().split())) for _ in range(Q)]
ll = [0]*N
ans = [0]*N
bb = [[i] for i in range(1,N+1)]
for i in l:
    bb[i[0]-1].append(i[1])
for i in m:
    ll[i[0]-1] += int(i[1])

# print("bb=",bb)
# print("ll=",ll)
for i in range(N):
    for k in range(len(bb[i])):
        if k == 0 :
            ans[i] += ll[i]
        else:
            ll[bb[i][k]-1] += ll[i]
print(*ans)

Fixed submission:
n, q = map(int, input().split())
ki = [0] * (n + 1)
for i in range(n - 1):
    a, b = map(int, input().split())
    ki[b] = a
# print("ki=",ki)

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

for i in range(1, n + 1):
    c[i] += c[ki[i]]
# print(c)

print(" ".join(map(str, c[1:])))

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int,input().split())
l = [list(map(int,input().split())) for _ in range(N-1)]
m = [list(map(int,input().split())) for _ in range(Q)]
ll = [0]*N
bb = [[i] for i in range(1,N+1)]
for i in l:
    bb[i[0]-1].append(i[1])
for i in m:
    ll[i[0]-1] += int(i[1])
ans = [0]*N
# print("bb=",bb)
# print("ll=",ll)
for i in range(N):
    for k in bb[i]:
        if k == i+1:
            ans[i] += ll[i]
        else:
            ll[k-1] += ll[i]
print(*ans)

Fixed submission:
n, q = map(int, input().split())
ki = [0] * (n + 1)
for i in range(n - 1):
    a, b = map(int, input().split())
    ki[b] = a
# print("ki=",ki)

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

for i in range(1, n + 1):
    c[i] += c[ki[i]]
# print(c)

print(" ".join(map(str, c[1:])))

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int,input().split())
l = [list(map(int,input().split())) for _ in range(N-1)]
m = [list(map(int,input().split())) for _ in range(Q)]
ll = [0]*N
bb = [[i] for i in range(1,N+1)]
for i in l:
    bb[i[0]-1].append(i[1])
for i in m:
    ll[i[0]-1] += int(i[1])
ans = [0]*N
# print("bb=",bb)
# print("ll=",ll)
for i in range(N):
    for k in bb[i]:
        if k == i+1:
            ans[i] += ll[i]
        else:
            ll[k-1] += ll[i]
print(*ans)

Fixed submission:
n, q = map(int, input().split())
ki = [0] * (n + 1)
for i in range(n - 1):
    a, b = map(int, input().split())
    ki[b] = a
# print("ki=",ki)

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

for i in range(1, n + 1):
    c[i] += c[ki[i]]
# print(c)

print(" ".join(map(str, c[1:])))

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int,input().split())
l = [list(map(int,input().split())) for _ in range(N-1)]
m = [list(map(int,input().split())) for _ in range(Q)]
ll = [0]*N
bb = [[i] for i in range(1,N+1)]
for i in l:
    bb[i[0]-1].append(i[1])
for i in m:
    ll[i[0]-1] += int(i[1])
ans = [0]*N
# print("bb=",bb)
# print("ll=",ll)
for i in range(N):
    for k in bb[i]:
        if k == i+1:
            ans[i] += ll[i]
        else:
            ll[k-1] += ll[i]
print(*ans)

Fixed submission:
n, q = map(int, input().split())
ki = [0] * (n + 1)
for i in range(n - 1):
    a, b = map(int, input().split())
    ki[b] = a
# print("ki=",ki)

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

for i in range(1, n + 1):
    c[i] += c[ki[i]]
# print(c)

print(" ".join(map(str, c[1:])))