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

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

ans = [-1] * n

def dfs(v, cnt):
    ans[v] = cnt + S[v]
    for i in G[v]:
        if ans[i] == -1: dfs(i, cnt + S[v])

dfs(0, 0)
print(*ans)

Fixed submission:
from collections import deque

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

ans = [-1] * n

def dfs(v):
    ans[v] = S[v]
    stack = [v]
    while stack:
        x = stack[-1]
        if len(G[x]) > 0:
            w = G[x].popleft()
            if ans[w] == -1:
                ans[w] = ans[x] + S[w]
                stack.append(w)
        else: stack.pop()

dfs(0)
print(*ans)

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

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

ans = [-1] * n

def dfs(v, cnt):
    ans[v] = cnt + S[v]
    for i in G[v]:
        if ans[i] == -1: dfs(i, cnt + S[v])

dfs(0, 0)
print(*ans)

Fixed submission:
from collections import deque

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

ans = [-1] * n

def dfs(v):
    ans[v] = S[v]
    stack = [v]
    while stack:
        x = stack[-1]
        if len(G[x]) > 0:
            w = G[x].popleft()
            if ans[w] == -1:
                ans[w] = ans[x] + S[w]
                stack.append(w)
        else: stack.pop()

dfs(0)
print(*ans)

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

ans = [-1] * n

def dfs(v, cnt):
    ans[v] = cnt + S[v]
    for i in G[v]:
        if ans[i] == -1: dfs(i, cnt + S[v])

dfs(0, 0)
print(*ans)

Fixed submission:
from collections import deque

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

ans = [-1] * n

def dfs(v):
    ans[v] = S[v]
    stack = [v]
    while stack:
        x = stack[-1]
        if len(G[x]) > 0:
            w = G[x].popleft()
            if ans[w] == -1:
                ans[w] = ans[x] + S[w]
                stack.append(w)
        else: stack.pop()

dfs(0)
print(*ans)