Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys

sys.setrecursionlimit(10 ** 8)
input = sys.stdin.readline


def dfs(now):
    seen[now] = True
    for next in branch[now]:
        if seen[next] is False:
            score[next] += score[now]
            dfs(next)


N, Q = map(int, input().split())
branch = [set() for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    branch[a - 1].add(b - 1)
    branch[b - 1].add(a - 1)
score = [0] * N
for _ in range(Q):
    p, x = map(int, input().split())
    score[p - 1] += x

seen = [False] * N
for i in range(N):
    if seen[i] is False:
        dfs(i)

print(*score)


Fixed submission:
#!/usr/bin/env python3
from sys import setrecursionlimit

setrecursionlimit(10 ** 8)


def dfs(now):
    seen[now] = True
    score[now] += operation[now]
    for next in branch[now]:
        if seen[next] is False:
            score[next] += score[now]
            dfs(next)


N, Q = map(int, input().split())
branch = [set() for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    branch[a - 1].add(b - 1)
    branch[b - 1].add(a - 1)
operation = [0] * N
for _ in range(Q):
    p, x = map(int, input().split())
    operation[p - 1] += x

seen = [False] * N
score = [0] * N
for i in range(N):
    if seen[i] is False:
        dfs(i)

for ans in score:
    print(ans, end=' ')

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
from collections import deque
from sys import setrecursionlimit

setrecursionlimit(10 ** 8)


def dfs(now):
    seen[now] = True
    for next in branch[now]:
        if seen[next] is False:
            tree[now].append(next)
            dfs(next)
    return tree


N, Q = map(int, input().split())
branch = [set() for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    branch[a - 1].add(b - 1)
    branch[b - 1].add(a - 1)
operation = [list(map(int, input().split())) for _ in range(Q)]

seen = [False] * N
tree = [[] for _ in range(N)]
for i in range(N):
    if seen[i] is False:
        dfs(i)
lst = []
for i in range(N):
    res = []
    tmp_lst = deque([i])
    while tmp_lst:
        now = tmp_lst.pop()
        res.append(now)
        for next in tree[now]:
            tmp_lst.append(next)
    lst.append(res)

score = [0 for _ in range(N)]
for q in operation:
    root, pnt = q
    root -= 1
    for i in lst[root]:
        score[i] += pnt

for ans in score:
    print(ans, end=' ')


Fixed submission:
#!/usr/bin/env python3
from sys import setrecursionlimit

setrecursionlimit(10 ** 8)


def dfs(now):
    seen[now] = True
    score[now] += operation[now]
    for next in branch[now]:
        if seen[next] is False:
            score[next] += score[now]
            dfs(next)


N, Q = map(int, input().split())
branch = [set() for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    branch[a - 1].add(b - 1)
    branch[b - 1].add(a - 1)
operation = [0] * N
for _ in range(Q):
    p, x = map(int, input().split())
    operation[p - 1] += x

seen = [False] * N
score = [0] * N
for i in range(N):
    if seen[i] is False:
        dfs(i)

for ans in score:
    print(ans, end=' ')

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
from collections import deque
from sys import setrecursionlimit

setrecursionlimit(10 ** 8)


def dfs(now):
    seen[now] = True
    for next in branch[now]:
        if seen[next] is False:
            tree[now].append(next)
            dfs(next)
    return tree


N, Q = map(int, input().split())
branch = [set() for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    branch[a - 1].add(b - 1)
    branch[b - 1].add(a - 1)
operation = [list(map(int, input().split())) for _ in range(Q)]

seen = [False] * N
tree = [[] for _ in range(N)]
for i in range(N):
    if seen[i] is False:
        dfs(i)
score = [0 for _ in range(N)]
for q in operation:
    root, pnt = q
    root -= 1
    tmp_lst = deque([root])
    while tmp_lst:
        now = tmp_lst.pop()
        score[now] += pnt
        for next in tree[now]:
            tmp_lst.append(next)

for ans in score:
    print(ans, end=' ')


Fixed submission:
#!/usr/bin/env python3
from sys import setrecursionlimit

setrecursionlimit(10 ** 8)


def dfs(now):
    seen[now] = True
    score[now] += operation[now]
    for next in branch[now]:
        if seen[next] is False:
            score[next] += score[now]
            dfs(next)


N, Q = map(int, input().split())
branch = [set() for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    branch[a - 1].add(b - 1)
    branch[b - 1].add(a - 1)
operation = [0] * N
for _ in range(Q):
    p, x = map(int, input().split())
    operation[p - 1] += x

seen = [False] * N
score = [0] * N
for i in range(N):
    if seen[i] is False:
        dfs(i)

for ans in score:
    print(ans, end=' ')