Buggy python submission (verdict: Runtime Error):
def add_node(tree, counter, ope, node, value):
    if node in ope:
        value += ope[node]
    counter[node - 1] += value

    if node in tree:
        for i in tree[node]:
            add_node(tree, counter, ope, i, value)


n, q = map(int, input().split())

tree = {}

for i in range(n - 1):
    a, b = map(int, input().split())
    if a not in tree:
        tree[a] = [b]
    else:
        tree[a].append(b)

ope = {}
for j in range(q):
    p, x = map(int, input().split())
    if p not in ope:
        ope[p] = x
    else:
        ope[p] += x

counter = [0] * n

# print(tree, ope)

# for k in ope:
add_node(tree, counter, ope, 1, 0)

print(*counter)



Fixed submission:
# def add_node(tree, counter, ope, node, value):
#     if node in ope:
#         value += ope[node]
#     counter[node - 1] += value

#     if node in tree:
#         for i in tree[node]:
#             add_node(tree, counter, ope, i, value)


n, q = map(int, input().split())

tree = {}

for i in range(n - 1):
    a, b = map(int, input().split())
    if a not in tree:
        tree[a] = [b]
    else:
        tree[a].append(b)

ope = {}
for j in range(q):
    p, x = map(int, input().split())
    if p not in ope:
        ope[p] = x
    else:
        ope[p] += x

counter = [0] * n

# print(tree, ope)

# for k in ope:
for i in range(1, n + 1):
    if i in ope:
        counter[i - 1] += ope[i]
    if i in tree:
        for j in tree[i]:
            counter[j - 1] += counter[i - 1]
    
# add_node(tree, counter, ope, 1, 0)

print(*counter)

Buggy python submission (verdict: Runtime Error):
def add_node(tree, counter, ope, node, value):
    if node in ope:
        value += ope[node]
    counter[node - 1] += value

    if node in tree:
        for i in tree[node]:
            add_node(tree, counter, ope, i, value)


n, q = map(int, input().split())

tree = {}

for i in range(n - 1):
    a, b = map(int, input().split())
    if a not in tree:
        tree[a] = [b]
    else:
        tree[a].append(b)

ope = {}
for j in range(q):
    p, x = map(int, input().split())
    if p not in ope:
        ope[p] = x
    else:
        ope[p] += x

counter = [0] * n

# print(tree, ope)

# for k in ope:
add_node(tree, counter, ope, 1, 0)

print(*counter)



Fixed submission:
# def add_node(tree, counter, ope, node, value):
#     if node in ope:
#         value += ope[node]
#     counter[node - 1] += value

#     if node in tree:
#         for i in tree[node]:
#             add_node(tree, counter, ope, i, value)


n, q = map(int, input().split())

tree = {}

for i in range(n - 1):
    a, b = map(int, input().split())
    if a not in tree:
        tree[a] = [b]
    else:
        tree[a].append(b)

ope = {}
for j in range(q):
    p, x = map(int, input().split())
    if p not in ope:
        ope[p] = x
    else:
        ope[p] += x

counter = [0] * n

# print(tree, ope)

# for k in ope:
for i in range(1, n + 1):
    if i in ope:
        counter[i - 1] += ope[i]
    if i in tree:
        for j in tree[i]:
            counter[j - 1] += counter[i - 1]
    
# add_node(tree, counter, ope, 1, 0)

print(*counter)

Buggy python submission (verdict: Runtime Error):
def add_node(tree, counter, value, node):
    counter[node - 1] += value
    if node in tree:
        for i in tree[node]:
            add_node(tree, counter, value, i)


n, q = map(int, input().split())

tree = {}

for i in range(n - 1):
    a, b = map(int, input().split())
    if a not in tree:
        tree[a] = [b]
    else:
        tree[a].append(b)

ope = {}
for j in range(q):
    p, x = map(int, input().split())
    if p not in ope:
        ope[p] = x
    else:
        ope[p] += x

counter = [0] * n

for k in ope:
    add_node(tree, counter, ope[k], k)

print(*counter)



Fixed submission:
# def add_node(tree, counter, ope, node, value):
#     if node in ope:
#         value += ope[node]
#     counter[node - 1] += value

#     if node in tree:
#         for i in tree[node]:
#             add_node(tree, counter, ope, i, value)


n, q = map(int, input().split())

tree = {}

for i in range(n - 1):
    a, b = map(int, input().split())
    if a not in tree:
        tree[a] = [b]
    else:
        tree[a].append(b)

ope = {}
for j in range(q):
    p, x = map(int, input().split())
    if p not in ope:
        ope[p] = x
    else:
        ope[p] += x

counter = [0] * n

# print(tree, ope)

# for k in ope:
for i in range(1, n + 1):
    if i in ope:
        counter[i - 1] += ope[i]
    if i in tree:
        for j in tree[i]:
            counter[j - 1] += counter[i - 1]
    
# add_node(tree, counter, ope, 1, 0)

print(*counter)