Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict


def calc_parents(N, adj_nodes, root=0):
    parents = [-1 for _ in range(N)]
    frontier = [root]
    parents[root] = root
    while len(frontier) > 0:
        node = frontier.pop()
        for child in adj_nodes[node]:
            if parents[child] >= 0:
                continue
            frontier.append(child)
            parents[child] = node
    return parents


def sum_counts(N, parents, counter_roots):
    counter = [0 for _ in range(N)]
    for node in range(N):
        current_node = node
        parent_node = parents[current_node]
        s = counter_roots[current_node]
        while current_node != parent_node:
            current_node = parent_node
            parent_node = parents[current_node]
            s += counter_roots[current_node]
        counter[node] += s
    return counter


def main():
    N, Q = list(map(int, input().split(' ')))
    adj_nodes = defaultdict(list)
    for _ in range(N - 1):
        a, b = list(map(int, input().split(' ')))
        a -= 1
        b -= 1
        adj_nodes[a].append(b)
        adj_nodes[b].append(a)
    parents = calc_parents(N, adj_nodes)
    counter_roots = [0 for _ in range(N)]
    for _ in range(Q):
        p, x = list(map(int, input().split(' ')))
        p -= 1
        counter_roots[p] += x
    counter = sum_counts(N, parents, counter_roots)
    print(' '.join(map(str, counter)))


if __name__ == '__main__':
    main()

Fixed submission:
from collections import defaultdict


def sum_counter(N, adj_nodes, counter_roots, root=0):
    parents = [-1 for _ in range(N)]
    counter = [0 for _ in range(N)]
    frontier = [root]
    counter[root] += counter_roots[root]
    parents[root] = root
    while len(frontier) > 0:
        parent = frontier.pop()
        for child in adj_nodes[parent]:
            if parents[child] >= 0:
                continue
            frontier.append(child)
            parents[child] = parent
            counter[child] += counter[parent] + counter_roots[child]
    return counter


def main():
    N, Q = list(map(int, input().split(' ')))
    adj_nodes = defaultdict(list)
    for _ in range(N - 1):
        a, b = list(map(int, input().split(' ')))
        a -= 1
        b -= 1
        adj_nodes[a].append(b)
        adj_nodes[b].append(a)
    counter_roots = [0 for _ in range(N)]
    for _ in range(Q):
        p, x = list(map(int, input().split(' ')))
        p -= 1
        counter_roots[p] += x
    c = sum_counter(N, adj_nodes, counter_roots)
    print(' '.join(map(str, c)))


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def calc_parents(N, adj_nodes, root=0):
    parents = [-1 for _ in range(N)]
    frontier = [root]
    parents[root] = root
    while len(frontier) > 0:
        node = frontier.pop()
        for child in adj_nodes[node]:
            if parents[child] >= 0:
                continue
            frontier.append(child)
            parents[child] = node
    return parents


def sum_counts(N, parents, counter_roots):
    counter = [0 for _ in range(N)]
    for node in range(N):
        current_node = node
        parent_node = parents[current_node]
        s = counter_roots[current_node]
        while current_node != parent_node:
            current_node = parent_node
            parent_node = parents[current_node]
            s += counter_roots[current_node]
        counter[node] += s
    return counter


def main():
    N, Q = list(map(int, input().split(' ')))
    adj_nodes = defaultdict(list)
    for _ in range(N - 1):
        a, b = list(map(int, input().split(' ')))
        a -= 1
        b -= 1
        adj_nodes[a].append(b)
        adj_nodes[b].append(a)
    parents = calc_parents(N, adj_nodes)
    counter_roots = [0 for _ in range(N)]
    for _ in range(Q):
        p, x = list(map(int, input().split(' ')))
        p -= 1
        counter_roots[p] += x
    counter = sum_counts(N, parents, counter_roots)
    print(' '.join(map(str, counter)))


if __name__ == '__main__':
    main()

Fixed submission:
from collections import defaultdict


def sum_counter(N, adj_nodes, counter_roots, root=0):
    parents = [-1 for _ in range(N)]
    counter = [0 for _ in range(N)]
    frontier = [root]
    counter[root] += counter_roots[root]
    parents[root] = root
    while len(frontier) > 0:
        parent = frontier.pop()
        for child in adj_nodes[parent]:
            if parents[child] >= 0:
                continue
            frontier.append(child)
            parents[child] = parent
            counter[child] += counter[parent] + counter_roots[child]
    return counter


def main():
    N, Q = list(map(int, input().split(' ')))
    adj_nodes = defaultdict(list)
    for _ in range(N - 1):
        a, b = list(map(int, input().split(' ')))
        a -= 1
        b -= 1
        adj_nodes[a].append(b)
        adj_nodes[b].append(a)
    counter_roots = [0 for _ in range(N)]
    for _ in range(Q):
        p, x = list(map(int, input().split(' ')))
        p -= 1
        counter_roots[p] += x
    c = sum_counter(N, adj_nodes, counter_roots)
    print(' '.join(map(str, c)))


if __name__ == '__main__':
    main()