Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# N: ノードの数
# Q: 数値をノードに付与する回数
N, Q = list(map(int, input().split()))

links =  [[] for x in range(N)]
values = [0 for _ in range(N)]

for i in range(N - 1):
    edge1, edge2 = [x - 1 for x in list(map(int, input().split()))]
    links[edge1].append(edge2)
    links[edge2].append(edge1)

for i in range(Q):
    node, val = list(map(int, input().split()))
    values[node - 1] += val

# 値の計算
queue = [(0, -1)]  # [(ノードID, 親ノードID)] のリスト (-1 は番兵)
while queue:
    node = queue[0]
    queue = queue[1:]

    for linked_node in links[node[0]]:
        if linked_node == node[1]:  # link が親ノード向けでなければ
            continue

        values[linked_node] += values[node[0]]
        queue.append((linked_node, node[0]))

print(*values)

Fixed submission:
# -*- coding: utf-8 -*-
# https://atcoder.jp/contests/abc138/tasks/abc138_d


def main():
    n, q = map(int, input().split())
    values = [0] * n
    links = [[] for _ in range(n)]

    for _ in range(n - 1):
        a, b = map(int, input().split())
        links[a - 1].append(b - 1)
        links[b - 1].append(a - 1)

    for _ in range(q):
        p, x = map(int, input().split())
        values[p - 1] += x

    s = [(0, -1)]
    while s:
        i, p = s.pop()
        for j in links[i]:
            if j == p:
                continue
            values[j] += values[i]
            s.append((j, i))

    print(*values)


main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# N: ノードの数
# Q: 数値をノードに付与する回数
N, Q = list(map(int, input().split()))

# {0: [], 1: [], ...} のような辞書を作る
links = { x:[] for x in range(N) }

values = [ 0 for _ in range(N) ]

for i in range(N - 1):
    edge1, edge2 = [x - 1 for x in list(map(int, input().split()))]
    links[edge1].append(edge2)
    links[edge2].append(edge1)

for i in range(Q):
    node, val = list(map(int, input().split()))
    values[node - 1] += val

# 値の計算
queue = [(0, -1)]  # [(ノードID, 親ノードID)] のリスト (-1 は番兵)
while queue:
    node = queue[0]
    queue = queue[1:]

    for linked_node in links[node[0]]:
        if linked_node == node[1]:  # link が親ノード向けでなければ
            continue

        values[linked_node] += values[node[0]]
        queue.append((linked_node, node[0]))

print(*values)

Fixed submission:
# -*- coding: utf-8 -*-
# https://atcoder.jp/contests/abc138/tasks/abc138_d


def main():
    n, q = map(int, input().split())
    values = [0] * n
    links = [[] for _ in range(n)]

    for _ in range(n - 1):
        a, b = map(int, input().split())
        links[a - 1].append(b - 1)
        links[b - 1].append(a - 1)

    for _ in range(q):
        p, x = map(int, input().split())
        values[p - 1] += x

    s = [(0, -1)]
    while s:
        i, p = s.pop()
        for j in links[i]:
            if j == p:
                continue
            values[j] += values[i]
            s.append((j, i))

    print(*values)


main()

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# https://atcoder.jp/contests/abc138/tasks/abc138_d

# It's a Python porting of ki.cpp
# Mainly to understand the algorithm by myself

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

tree_link = [None] * 200005
answer = [0] * N


def dfs(v, p=-1):
    for link in tree_link[v]:
        if link == p:  # 親ノードであれば continue
            continue
        answer[link] += answer[v]
        dfs(link, v)


# 双方向の辺を作る
for i in range(N - 1):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1

    if tree_link[a]:
        tree_link[a].append(b)
    else:
        tree_link[a] = [b]

    if tree_link[b]:
        tree_link[b].append(a)
    else:
        tree_link[b] = [a]

# 頂点に値を足し込む
for i in range(Q):
    p, x = list(map(int, input().split()))
    answer[p - 1] += x

# 計算
dfs(0)

# 出力
print(" ".join([str(answer[i]) for i in range(N)]))


Fixed submission:
# -*- coding: utf-8 -*-
# https://atcoder.jp/contests/abc138/tasks/abc138_d


def main():
    n, q = map(int, input().split())
    values = [0] * n
    links = [[] for _ in range(n)]

    for _ in range(n - 1):
        a, b = map(int, input().split())
        links[a - 1].append(b - 1)
        links[b - 1].append(a - 1)

    for _ in range(q):
        p, x = map(int, input().split())
        values[p - 1] += x

    s = [(0, -1)]
    while s:
        i, p = s.pop()
        for j in links[i]:
            if j == p:
                continue
            values[j] += values[i]
            s.append((j, i))

    print(*values)


main()

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# https://atcoder.jp/contests/abc138/tasks/abc138_d

# It's a Python porting of ki.cpp
# Mainly to understand the algorithm by myself

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

tree_link = [None] * 100000
answer = [0] * N


def dfs(v, p=-1):
    for link in tree_link[v]:
        if link == p:  # 親ノードであれば continue
            continue
        answer[link] += answer[v]
        dfs(link, v)


# 双方向の辺を作る
for i in range(N - 1):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1

    if tree_link[a]:
        tree_link[a].append(b)
    else:
        tree_link[a] = [b]

    if tree_link[b]:
        tree_link[b].append(a)
    else:
        tree_link[b] = [a]

# 頂点に値を足し込む
for i in range(Q):
    p, x = list(map(int, input().split()))
    answer[p - 1] += x

# 計算
dfs(0)

# 出力
print(" ".join([str(answer[i]) for i in range(N)]))


Fixed submission:
# -*- coding: utf-8 -*-
# https://atcoder.jp/contests/abc138/tasks/abc138_d


def main():
    n, q = map(int, input().split())
    values = [0] * n
    links = [[] for _ in range(n)]

    for _ in range(n - 1):
        a, b = map(int, input().split())
        links[a - 1].append(b - 1)
        links[b - 1].append(a - 1)

    for _ in range(q):
        p, x = map(int, input().split())
        values[p - 1] += x

    s = [(0, -1)]
    while s:
        i, p = s.pop()
        for j in links[i]:
            if j == p:
                continue
            values[j] += values[i]
            s.append((j, i))

    print(*values)


main()

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-


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


class Node:
    val = 0
    children = []

    def __init__(self, val, children):
        self.val = val
        self.children = children


# 木を作る
tree = {}
for i in range(N - 1):
    a, b = list(map(int, input().split()))
    left_node = tree.get(a, False)
    if left_node:
        left_node.children.append(b)
    else:
        tree[a] = Node(0, [b])

    right_node = tree.get(b, False)
    if not right_node:
        tree[b] = Node(0, [])


def add_val_recurse(node: Node, val):
    if node:
        node.val += val
        [add_val_recurse(tree.get(child, None), val) for child in node.children]


# 木に値を詰める
for i in range(Q):
    node, val = list(map(int, input().split()))
    add_val_recurse(tree.get(node, None), val)


print(" ".join([str(tree[key].val) for key in sorted(list(tree.keys()))]))


Fixed submission:
# -*- coding: utf-8 -*-
# https://atcoder.jp/contests/abc138/tasks/abc138_d


def main():
    n, q = map(int, input().split())
    values = [0] * n
    links = [[] for _ in range(n)]

    for _ in range(n - 1):
        a, b = map(int, input().split())
        links[a - 1].append(b - 1)
        links[b - 1].append(a - 1)

    for _ in range(q):
        p, x = map(int, input().split())
        values[p - 1] += x

    s = [(0, -1)]
    while s:
        i, p = s.pop()
        for j in links[i]:
            if j == p:
                continue
            values[j] += values[i]
            s.append((j, i))

    print(*values)


main()