Buggy python submission (verdict: Runtime Error):
nodeN, tryN = map(int, input().split())
dic_cp = {}
sum_value =[0] * (nodeN + 1)
for _ in range(nodeN - 1):
    parent, child = map(int, input().split())
    dic_cp[child] = parent


for _ in range(tryN):
    no, value = map(int, input().split())
    sum_value[no] += value

ans = []
for i in range(1, nodeN + 1):
    wa = sum_value[i]
    k = i
    while k > 1:
        parent = dic_cp[k]
        wa += sum_value[parent]
        k = parent
    ans.append(wa)

print(' '.join(map(str, ans)))




Fixed submission:
class Node:
    def __init__(self, index):
        self.count = 0
        self.fr = -1
        self.index = index


N, Q = map(int, input().split())
node = [Node(i) for i in range(N)]
for i in range(N - 1):
    fr, to = map(int, input().split())
    node[to - 1].fr = fr - 1

for i in range(Q):
    fr, c = map(int, input().split())
    node[fr - 1].count += c

print(node[0].count, end=' ')

for i in range(1, N):
    node[i].count += node[node[i].fr].count
    if not i == N:
        print(node[i].count, end=' ')
    else:
        print(node[i].count)

Buggy python submission (verdict: Runtime Error):
    class Node:
        def __init__(self, index):
            self.count = 0
            self.fr = -1
            self.index = index
     
     
    N, Q = map(int, input().split())
    node = [Node(i) for i in range(N)]
    for i in range(N - 1):
        fr, to = map(int, input().split())
        node[to - 1].fr = fr - 1
     
    for i in range(Q):
        fr, c = map(int, input().split())
        node[fr - 1].count += c
     
    print(node[0].count, end=' ')
     
    for i in range(1, N):
        node[i].count += node[node[i].fr].count
        if not i == N:
            print(node[i].count, end=' ')
        else:
            print(node[i].count)

Fixed submission:
class Node:
    def __init__(self, index):
        self.count = 0
        self.fr = -1
        self.index = index


N, Q = map(int, input().split())
node = [Node(i) for i in range(N)]
for i in range(N - 1):
    fr, to = map(int, input().split())
    node[to - 1].fr = fr - 1

for i in range(Q):
    fr, c = map(int, input().split())
    node[fr - 1].count += c

print(node[0].count, end=' ')

for i in range(1, N):
    node[i].count += node[node[i].fr].count
    if not i == N:
        print(node[i].count, end=' ')
    else:
        print(node[i].count)

Buggy python submission (verdict: Time Limit Exceeded):
class Node:
    def __init__(self, index):
        self.count = 0
        self.fr = -1
        self.index = index


N, Q = map(int, input().split())
node = [Node(i) for i in range(N)]
for i in range(N - 1):
    fr, to = map(int, input().split())
    node[to - 1].fr = fr - 1

for i in range(Q):
    fr, c = map(int, input().split())
    node[fr- 1].count += c
    
for i in range(N):
    x = node[i].count
    next = node[i].fr
    while next != -1:
        x += node[next].count
        next = node[next].fr
    if not i == N:
        print(x, end=' ')
    else:
        print(x)





Fixed submission:
class Node:
    def __init__(self, index):
        self.count = 0
        self.fr = -1
        self.index = index


N, Q = map(int, input().split())
node = [Node(i) for i in range(N)]
for i in range(N - 1):
    fr, to = map(int, input().split())
    node[to - 1].fr = fr - 1

for i in range(Q):
    fr, c = map(int, input().split())
    node[fr - 1].count += c

print(node[0].count, end=' ')

for i in range(1, N):
    node[i].count += node[node[i].fr].count
    if not i == N:
        print(node[i].count, end=' ')
    else:
        print(node[i].count)

Buggy python submission (verdict: Runtime Error):
    class Node:
        def __init__(self, index):
            self.count = 0
            self.fr = -1
            self.index = index
     
     
    N, Q = map(int, input().split())
    node = [Node(i) for i in range(N)]
    for i in range(N - 1):
        fr, to = map(int, input().split())
        node[to - 1].fr = fr - 1
     
    for i in range(Q):
        fr, c = map(int, input().split())
        node[fr- 1].count += c
     
    for i in range(N):
        x = node[i].count
        next = node[i].fr
        while next != -1:
            x += node[next].count
            next = node[next].fr
        if not i == N:
            print(x, end=' ')
        else:
            print(x)

Fixed submission:
class Node:
    def __init__(self, index):
        self.count = 0
        self.fr = -1
        self.index = index


N, Q = map(int, input().split())
node = [Node(i) for i in range(N)]
for i in range(N - 1):
    fr, to = map(int, input().split())
    node[to - 1].fr = fr - 1

for i in range(Q):
    fr, c = map(int, input().split())
    node[fr - 1].count += c

print(node[0].count, end=' ')

for i in range(1, N):
    node[i].count += node[node[i].fr].count
    if not i == N:
        print(node[i].count, end=' ')
    else:
        print(node[i].count)

Buggy python submission (verdict: Time Limit Exceeded):
class Node:
    def __init__(self, index):
        self.count = 0
        self.fr = -1
        self.index = index


N, Q = map(int, input().split())
node = [Node(i) for i in range(N)]
for i in range(N - 1):
    fr, to = map(int, input().split())
    node[to - 1].fr = fr - 1

for i in range(Q):
    fr, c = map(int, input().split())
    node[fr- 1].count += c

for i in range(N):
    x = node[i].count
    next = node[i].fr
    while next != -1:
        x += node[next].count
        next = node[next].fr
    if not i == N:
        print(x, end=' ')
    else:
        print(x)


Fixed submission:
class Node:
    def __init__(self, index):
        self.count = 0
        self.fr = -1
        self.index = index


N, Q = map(int, input().split())
node = [Node(i) for i in range(N)]
for i in range(N - 1):
    fr, to = map(int, input().split())
    node[to - 1].fr = fr - 1

for i in range(Q):
    fr, c = map(int, input().split())
    node[fr - 1].count += c

print(node[0].count, end=' ')

for i in range(1, N):
    node[i].count += node[node[i].fr].count
    if not i == N:
        print(node[i].count, end=' ')
    else:
        print(node[i].count)

Buggy python submission (verdict: Runtime Error):
class Node:
    def __init__(self, index):
        self.count = 0
        self.next = []
        self.index = index


def f(node, count, index):
    node[index].count += count
    for i in node[index].next:
        f(node, count, i)


N, Q = map(int, input().split())
node = [Node(i) for i in range(N)]
for i in range(N - 1):
    fr, to = map(int, input().split())
    node[fr - 1].next.append(to - 1)

for i in range(Q):
    fr, c = map(int, input().split())
    f(node, c, fr - 1)

print(' '.join([str(n.count) for n in node]))


Fixed submission:
class Node:
    def __init__(self, index):
        self.count = 0
        self.fr = -1
        self.index = index


N, Q = map(int, input().split())
node = [Node(i) for i in range(N)]
for i in range(N - 1):
    fr, to = map(int, input().split())
    node[to - 1].fr = fr - 1

for i in range(Q):
    fr, c = map(int, input().split())
    node[fr - 1].count += c

print(node[0].count, end=' ')

for i in range(1, N):
    node[i].count += node[node[i].fr].count
    if not i == N:
        print(node[i].count, end=' ')
    else:
        print(node[i].count)