Buggy python submission (verdict: Time Limit Exceeded):
import sys

sys.setrecursionlimit(10 ** 6)

N, Q = map(int, input().split())

E = [[] for _ in range(N + 1)]
X = [0 for _ in range(N + 1)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    E[a].append(b)
    E[b].append(a)

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

visited = [False for _ in range(N + 1)]
visited[1] = True


def add(i, val):
    X[i] += val
    for to in E[i]:
        if visited[to]:
            continue
        visited[to] = True
        add(to, X[i])


add(1, 0)

print(*X[1:])


Fixed submission:
import sys

N, Q = map(int, input().split())

E = [[] for _ in range(N + 1)]
X = [0 for _ in range(N + 1)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    E[a].append(b)
    E[b].append(a)

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

stack = [1]
visited = [False for _ in range(N + 1)]
visited[1] = True

while stack:
    i = stack.pop()
    for j in E[i]:
        if visited[j]:
            continue
        visited[j] = True
        stack.append(j)
        X[j] += X[i]

print(*X[1:])

Buggy python submission (verdict: Time Limit Exceeded):
import sys

sys.setrecursionlimit(10 ** 6)

N, Q = map(int, input().split())

E = [[] for _ in range(N + 1)]
X = [0 for _ in range(N + 1)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    E[a].append(b)
    E[b].append(a)

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

visited = [False for _ in range(N + 1)]
visited[1] = True


def add(i, val):
    X[i] += val
    for to in E[i]:
        if visited[to]:
            continue
        visited[to] = True
        add(to, X[i])


add(1, 0)

print(*X[1:])


Fixed submission:
import sys

N, Q = map(int, input().split())

E = [[] for _ in range(N + 1)]
X = [0 for _ in range(N + 1)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    E[a].append(b)
    E[b].append(a)

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

stack = [1]
visited = [False for _ in range(N + 1)]
visited[1] = True

while stack:
    i = stack.pop()
    for j in E[i]:
        if visited[j]:
            continue
        visited[j] = True
        stack.append(j)
        X[j] += X[i]

print(*X[1:])

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())

E = [[] for _ in range(N + 1)]
X = [0 for _ in range(N + 1)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    E[a].append(b)
    E[b].append(a)

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

visited = [False for _ in range(N + 1)]
visited[1] = True


def add(i, val):
    X[i] += val
    for to in E[i]:
        if visited[to]:
            continue
        visited[to] = True
        add(to, X[i])


add(1, 0)

print(*X[1:])


Fixed submission:
import sys

N, Q = map(int, input().split())

E = [[] for _ in range(N + 1)]
X = [0 for _ in range(N + 1)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    E[a].append(b)
    E[b].append(a)

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

stack = [1]
visited = [False for _ in range(N + 1)]
visited[1] = True

while stack:
    i = stack.pop()
    for j in E[i]:
        if visited[j]:
            continue
        visited[j] = True
        stack.append(j)
        X[j] += X[i]

print(*X[1:])