Buggy python submission (verdict: Time Limit Exceeded):
# def main():
#     N, Q = list(map(int, input().split()))
#     parents = [[] for i in range(N+1)]
#     ans = [0] * (N+1)

#     for i in range(N-1):
#         a, b = list(map(int, input().split()))
#         parents[b].append(a)

#     for i in range(Q):
#         p, x = list(map(int, input().split()))
#         ans[p] += x

#     print(parents[1:])

#     for i in range(1, N+1):
#         for p in parents[i]:
#             ans[i] += ans[p]

#     print(*ans[1:])

import queue


def main():
    N, Q = map(int, input().split())
    tree = [[] for i in range(N+1)]
    ans = [0] * (N+1)
    visit = [False]*(N+1)

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

    for i in range(Q):
        p, x = map(int, input().split())
        ans[p] += x

    q = queue.Queue()
    q.put(1)
    visit[1] = True

    while (not q.empty()):
        n = q.get()
        # print(tree[n])
        for i in tree[n]:
            if visit[i] is False:
                ans[i] += ans[n]
                # print(i, '+=', n)
                visit[i] = True
                q.put(i)

    print(*ans[1:])


if __name__ == '__main__':
    main()


Fixed submission:
import sys
import queue
input = sys.stdin.readline
N, Q = map(int, input().split())
 
tree = [[] for i in range(N+1)]
values = [0] * (N+1)
visit = [False]*(N+1)
for _ in range(N-1):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)
 
for _ in range(Q):
    p, x = map(int, input().split())
    values[p] += x
 
 
q = queue.Queue()
q.put(1)
visit[1] = True
while (not q.empty()):
    now = q.get()
    for next in tree[now]:
        if not visit[next]:
            values[next] += values[now]
            visit[next] = True
            q.put(next)
 
values = values[1:]
print(" ".join(map(str, values)))

Buggy python submission (verdict: Time Limit Exceeded):
# def main():
#     N, Q = list(map(int, input().split()))
#     parents = [[] for i in range(N+1)]
#     ans = [0] * (N+1)

#     for i in range(N-1):
#         a, b = list(map(int, input().split()))
#         parents[b].append(a)

#     for i in range(Q):
#         p, x = list(map(int, input().split()))
#         ans[p] += x

#     print(parents[1:])

#     for i in range(1, N+1):
#         for p in parents[i]:
#             ans[i] += ans[p]

#     print(*ans[1:])

import queue


def main():
    N, Q = list(map(int, input().split()))
    tree = [[] for i in range(N+1)]
    ans = [0] * (N+1)
    visit = [False]*(N+1)

    for i in range(N-1):
        a, b = list(map(int, input().split()))
        tree[a].append(b)
        tree[b].append(a)

    for i in range(Q):
        p, x = list(map(int, input().split()))
        ans[p] += x

    q = queue.Queue()
    q.put(1)
    visit[1] = True

    while (not q.empty()):
        n = q.get()
        # print(tree[n])
        for i in tree[n]:
            if visit[i] is False:
                ans[i] += ans[n]
                # print(i, '+=', n)
                visit[i] = True
                q.put(i)

    print(*ans[1:])


if __name__ == '__main__':
    main()


Fixed submission:
import sys
import queue
input = sys.stdin.readline
N, Q = map(int, input().split())
 
tree = [[] for i in range(N+1)]
values = [0] * (N+1)
visit = [False]*(N+1)
for _ in range(N-1):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)
 
for _ in range(Q):
    p, x = map(int, input().split())
    values[p] += x
 
 
q = queue.Queue()
q.put(1)
visit[1] = True
while (not q.empty()):
    now = q.get()
    for next in tree[now]:
        if not visit[next]:
            values[next] += values[now]
            visit[next] = True
            q.put(next)
 
values = values[1:]
print(" ".join(map(str, values)))

Buggy python submission (verdict: Runtime Error):
def main():
    N, Q = list(map(int, input().split()))
    parents = {}
    ans = [0] * N

    for i in range(N-1):
        a, b = list(map(int, input().split()))
        parents[b-1] = a - 1

    for i in range(Q):
        p, x = list(map(int, input().split()))
        ans[p-1] += x

    for i in range(1, N):
        ans[i] += ans[parents[i]]

    print(' '.join(map(str, ans)))


if __name__ == '__main__':
    main()


Fixed submission:
import sys
import queue
input = sys.stdin.readline
N, Q = map(int, input().split())
 
tree = [[] for i in range(N+1)]
values = [0] * (N+1)
visit = [False]*(N+1)
for _ in range(N-1):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)
 
for _ in range(Q):
    p, x = map(int, input().split())
    values[p] += x
 
 
q = queue.Queue()
q.put(1)
visit[1] = True
while (not q.empty()):
    now = q.get()
    for next in tree[now]:
        if not visit[next]:
            values[next] += values[now]
            visit[next] = True
            q.put(next)
 
values = values[1:]
print(" ".join(map(str, values)))

Buggy python submission (verdict: Runtime Error):
def main():
    N, Q = list(map(int, input().split()))
    nodes = [None] * N
    ans = [0] * N

    for i in range(N-1):
        a, b = list(map(int, input().split()))

        if nodes[a-1] is None:
            nodes[a-1] = []

        nodes[a-1].append(b-1)

    # print()
    # print(nodes)

    for i in range(Q):
        p, x = list(map(int, input().split()))
        li = nodes[p-1]

        ans[p-1] += x

        if li is None:
            continue

        queue = li.copy()
        while len(queue) != 0:
            # print(queue)
            n = queue.pop(0)
            ans[n] += x

            if nodes[n] is not None:
                for next_n in nodes[n]:
                    queue.append(next_n)
        # print(i, ans)

    print(' '.join(map(str, ans)))


if __name__ == '__main__':
    main()


Fixed submission:
import sys
import queue
input = sys.stdin.readline
N, Q = map(int, input().split())
 
tree = [[] for i in range(N+1)]
values = [0] * (N+1)
visit = [False]*(N+1)
for _ in range(N-1):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)
 
for _ in range(Q):
    p, x = map(int, input().split())
    values[p] += x
 
 
q = queue.Queue()
q.put(1)
visit[1] = True
while (not q.empty()):
    now = q.get()
    for next in tree[now]:
        if not visit[next]:
            values[next] += values[now]
            visit[next] = True
            q.put(next)
 
values = values[1:]
print(" ".join(map(str, values)))

Buggy python submission (verdict: Runtime Error):
N, Q = list(map(int, input().split()))
p = [0] * Q
x = [0] * Q
nodes = [None] * N
ans = [0] * N

for i in range(N-1):
    a, b = list(map(int, input().split()))

    if nodes[a-1] is None:
         nodes[a-1] = []

    nodes[a-1].append(b-1)

# print()
# print(nodes)

for i in range(Q):
    p, x = list(map(int, input().split()))
    li = nodes[p-1]

    ans[p-1] += x

    if li is None:
        continue

    queue = li.copy()
    while len(queue) != 0:
        n = queue.pop(0)
        ans[n] += x

        if nodes[n] is not None:
            for next_n in nodes[n]:
                queue.append(next_n)

    # print(i, ans)

print(' '.join(map(str, ans)))


Fixed submission:
import sys
import queue
input = sys.stdin.readline
N, Q = map(int, input().split())
 
tree = [[] for i in range(N+1)]
values = [0] * (N+1)
visit = [False]*(N+1)
for _ in range(N-1):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)
 
for _ in range(Q):
    p, x = map(int, input().split())
    values[p] += x
 
 
q = queue.Queue()
q.put(1)
visit[1] = True
while (not q.empty()):
    now = q.get()
    for next in tree[now]:
        if not visit[next]:
            values[next] += values[now]
            visit[next] = True
            q.put(next)
 
values = values[1:]
print(" ".join(map(str, values)))