Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
ab = [[] for _ in range(n)]
px = [0 for _ in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    ab[a - 1].append(b - 1)
    ab[b - 1].append(a - 1)
for i in range(q):
    p, x = map(int, input().split())
    px[p - 1] += x

ans = px
queue = [(0, 0)]

while len(queue) > 0:
    prev, a = queue.pop(0)
    for c in ab[a]:
        if c != prev:
            ans[c] += ans[a]
            queue.append((a, c))

print(*ans)


Fixed submission:
from collections import deque

n, q = map(int, input().split())
ab = [[] for _ in range(n)]
px = [0 for _ in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    ab[a - 1].append(b - 1)
    ab[b - 1].append(a - 1)
for i in range(q):
    p, x = map(int, input().split())
    px[p - 1] += x

ans = px
queue = deque([(0, 0)])
while len(queue) > 0:
    prev, a = queue.pop()
    for c in ab[a]:
        if c != prev:
            ans[c] += ans[a]
            queue.append((a, c))

print(*ans)

Buggy python submission (verdict: Runtime Error):
n, q = map(int, input().split())
ab = [[] for _ in range(n)]
px = [0 for _ in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    ab[a - 1].append(b - 1)
    ab[b - 1].append(a - 1)
for i in range(q):
    p, x = map(int, input().split())
    px[p - 1] += x

visited = [False for _ in range(n)]


def dfs(current):
    for c in ab[current]:
        if visited[c]:
            continue
        ans[c] += ans[current]
        visited[c] = True
        dfs(c)


ans = px
visited[0] = True
dfs(0)
print(*ans)


Fixed submission:
from collections import deque

n, q = map(int, input().split())
ab = [[] for _ in range(n)]
px = [0 for _ in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    ab[a - 1].append(b - 1)
    ab[b - 1].append(a - 1)
for i in range(q):
    p, x = map(int, input().split())
    px[p - 1] += x

ans = px
queue = deque([(0, 0)])
while len(queue) > 0:
    prev, a = queue.pop()
    for c in ab[a]:
        if c != prev:
            ans[c] += ans[a]
            queue.append((a, c))

print(*ans)

Buggy python submission (verdict: Runtime Error):
n, q = map(int, input().split())
ab = [[] for _ in range(n)]
px = [0 for _ in range(n)]
ans = [0 for _ in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    ab[a - 1].append(b - 1)
for i in range(q):
    p, x = map(int, input().split())
    px[p - 1] += x


def dfs(current, v):
    vv = v + px[current]
    ans[current] = vv
    for c in ab[current]:
        dfs(c, vv)


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


Fixed submission:
from collections import deque

n, q = map(int, input().split())
ab = [[] for _ in range(n)]
px = [0 for _ in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    ab[a - 1].append(b - 1)
    ab[b - 1].append(a - 1)
for i in range(q):
    p, x = map(int, input().split())
    px[p - 1] += x

ans = px
queue = deque([(0, 0)])
while len(queue) > 0:
    prev, a = queue.pop()
    for c in ab[a]:
        if c != prev:
            ans[c] += ans[a]
            queue.append((a, c))

print(*ans)

Buggy python submission (verdict: Runtime Error):
n, q = map(int, input().split())
ab = [[] for _ in range(n)]
pq = [0 for _ in range(n)]
ans = [0 for _ in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    ab[a - 1].append(b - 1)
for i in range(q):
    p, q = map(int, input().split())
    pq[p - 1] += q


def dfs(parent, v):
    vv = v + pq[parent]
    ans[parent] = vv
    for c in ab[parent]:
        dfs(c, vv)


dfs(0, 0)
for a in ans:
    print(a)


Fixed submission:
from collections import deque

n, q = map(int, input().split())
ab = [[] for _ in range(n)]
px = [0 for _ in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    ab[a - 1].append(b - 1)
    ab[b - 1].append(a - 1)
for i in range(q):
    p, x = map(int, input().split())
    px[p - 1] += x

ans = px
queue = deque([(0, 0)])
while len(queue) > 0:
    prev, a = queue.pop()
    for c in ab[a]:
        if c != prev:
            ans[c] += ans[a]
            queue.append((a, c))

print(*ans)