Buggy python submission (verdict: Time Limit Exceeded):
import sys

sys.setrecursionlimit(10 ** 6)

class Node(object):
    def __init__(self):
        self.value = 0
        self.children_id = []

    def set_child(self, child_id):
        self.children_id.append(child_id)

    def add_number(self, n):
        self.value += n
        for child_id in self.children_id:
            nodes[child_id].add_number(n)

    def get_value(self):
        return self.value

N, Q = map(int, sys.stdin.readline().rstrip().split())

nodes = []
for i in range(N + 1):
    nodes.append(Node())

for j in range(N - 1):
    parent, child = map(int, sys.stdin.readline().rstrip().split())
    nodes[parent].set_child(child)

for _ in range(Q):
    parent, number = map(int, sys.stdin.readline().rstrip().split())
    nodes[parent].add_number(number)

res = []
for k in range(1, N + 1):
    res.append(nodes[k].get_value())

print(*res, sep=' ')


Fixed submission:
N, Q = map(int, input().split())

nodes = [0 for _ in range(N + 1)]

branches = []
for j in range(N - 1):
    parent, child = map(int, input().split())
    branches.append([parent, child])

for _ in range(Q):
    parent, number = map(int, input().split())
    nodes[parent] += number

branches.sort()

for branch in branches:
    parent = branch[0]
    child = branch[1]
    nodes[child] += nodes[parent]

print(*nodes[1:], sep=' ')

Buggy python submission (verdict: Time Limit Exceeded):
import sys

sys.setrecursionlimit(10 ** 6)

class Node(object):
    def __init__(self):
        self.value = 0
        self.children_id = []

    def set_child(self, child_id):
        self.children_id.append(child_id)

    def add_number(self, n):
        self.value += n
        for child_id in self.children_id:
            nodes[child_id].add_number(n)

    def get_value(self):
        return self.value

N, Q = map(int, sys.stdin.readline().rstrip().split())

nodes = []
for i in range(N + 1):
    nodes.append(Node())

for j in range(N - 1):
    parent, child = map(int, sys.stdin.readline().rstrip().split())
    nodes[parent].set_child(child)

for _ in range(Q):
    parent, number = map(int, sys.stdin.readline().rstrip().split())
    nodes[parent].add_number(number)

res = []
for k in range(1, N + 1):
    res.append(nodes[k].get_value())

print(*res, sep=' ')


Fixed submission:
N, Q = map(int, input().split())

nodes = [0 for _ in range(N + 1)]

branches = []
for j in range(N - 1):
    parent, child = map(int, input().split())
    branches.append([parent, child])

for _ in range(Q):
    parent, number = map(int, input().split())
    nodes[parent] += number

branches.sort()

for branch in branches:
    parent = branch[0]
    child = branch[1]
    nodes[child] += nodes[parent]

print(*nodes[1:], sep=' ')

Buggy python submission (verdict: Time Limit Exceeded):
import sys

sys.setrecursionlimit(10 ** 6)

class Node(object):
    def __init__(self, id):
        self.id = id
        self.value = 0
        self.parent_id = []
        self.children_id = []

    def set_parent(self, parent_id):
        self.parent_id.append(parent_id)

    def set_child(self, child_id):
        self.children_id.append(child_id)

    def add_number(self, n):
        self.value += n
        for child_id in self.children_id:
            nodes[child_id].add_number(n)

    def get_value(self):
        return self.value


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

nodes = []
for i in range(N + 1):
    nodes.append(Node(i))

for j in range(N - 1):
    parent, child = map(int, input().split())
    nodes[parent].set_child(child)
    nodes[child].set_parent(parent)

for _ in range(Q):
    parent, number = map(int, input().split())
    nodes[parent].add_number(number)

res = []
for k in range(1, N + 1):
    res.append(nodes[k].get_value())

print(*res, sep=' ')


Fixed submission:
N, Q = map(int, input().split())

nodes = [0 for _ in range(N + 1)]

branches = []
for j in range(N - 1):
    parent, child = map(int, input().split())
    branches.append([parent, child])

for _ in range(Q):
    parent, number = map(int, input().split())
    nodes[parent] += number

branches.sort()

for branch in branches:
    parent = branch[0]
    child = branch[1]
    nodes[child] += nodes[parent]

print(*nodes[1:], sep=' ')