Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())

class Node:
    def __init__(self, root):
        self.root = root
        self.children = []
        self.val = 0

    def add_child(self, child_node):
        self.children.append(child_node)
        if self.root is not None:
            self.root.add_child(child_node)

    def calc(self):
        if self.root is not None:
            self.val += self.root.val
        return self.val

nodes = [Node(None)] * n

for i in range(1, n):
    a, b = map(int, input().split())
    a_node = nodes[a - 1]
    nodes[b - 1] = Node(a_node)
    a_node.add_child(nodes[b - 1])

for j in range(q):
    p, x = map(int, input().split())
    node = nodes[p - 1]
    node.val += x

res = []
for node in nodes:
    res.append(str(node.calc()))
print(" ".join(res))

Fixed submission:
n, q = map(int, input().split())

children_map = [None] * n
vals = [0] * n

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

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

res = []
for i in range(n):
    parent = children_map[i]
    if parent is not None:
        vals[i] += vals[parent]
    res.append(str(vals[i]))

print(" ".join(res))

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())

class Node:
    def __init__(self, root):
        self.root = root
        self.children = []
        self.val = 0

    def add_child(self, child_node):
        self.children.append(child_node)
        if self.root is not None:
            self.root.add_child(child_node)

    def calc(self):
        res = self.val
        curr = self
        while True:
            root = curr.root
            if root is None:
                break
            res += root.val
            curr = root
        return res

nodes = [Node(None)] * n

for i in range(1, n):
    a, b = map(int, input().split())
    a_node = nodes[a - 1]
    nodes[b - 1] = Node(a_node)
    a_node.add_child(nodes[b - 1])

for j in range(q):
    p, x = map(int, input().split())
    node = nodes[p - 1]
    node.val += x
    # children = node.children
    # for child in children:
    #     child.val += x

res = []
for node in nodes:
    res.append(str(node.calc()))
print(" ".join(res))

Fixed submission:
n, q = map(int, input().split())

children_map = [None] * n
vals = [0] * n

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

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

res = []
for i in range(n):
    parent = children_map[i]
    if parent is not None:
        vals[i] += vals[parent]
    res.append(str(vals[i]))

print(" ".join(res))

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())

class Node:
    def __init__(self, root):
        self.root = root
        self.children = []
        self.val = 0

    def set_root(self, root_node):
        self.root = root_node

    def add_child(self, child_node):
        self.children.append(child_node)
        if self.root is not None:
            self.root.add_child(child_node)

nodes = [Node(None)] * n

for i in range(1, n):
    a, b = map(int, input().split())
    a_node = nodes[a - 1]
    nodes[b - 1] = Node(a_node)
    a_node.add_child(nodes[b - 1])

for j in range(q):
    p, x = map(int, input().split())
    node = nodes[p - 1]
    node.val += x
    children = node.children
    for child in children:
        child.val += x

res = []
for node in nodes:
    res.append(str(node.val))
print(" ".join(res))

Fixed submission:
n, q = map(int, input().split())

children_map = [None] * n
vals = [0] * n

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

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

res = []
for i in range(n):
    parent = children_map[i]
    if parent is not None:
        vals[i] += vals[parent]
    res.append(str(vals[i]))

print(" ".join(res))

Buggy python submission (verdict: Runtime Error):
n, q = map(int, input().split())

class Node:
    def __init__(self, root):
        self.root = root
        self.children = []
        self.val = 0

    def add_child(self, child_node):
        self.children.append(child_node)
        if self.root is not None:
            self.root.add_child(child_node)

nodes = [None] * n
nodes[0] = Node(None)

for i in range(1, n):
    a, b = map(int, input().split())
    a_node = nodes[a - 1]
    if nodes[b - 1] is None:
        b_node = Node(a_node)
        nodes[b - 1] = b_node
    a_node.add_child(nodes[b - 1])

for j in range(q):
    p, x = map(int, input().split())
    node = nodes[p - 1]
    if node is None:
        continue
    node.val += x
    children = node.children
    for child in children:
        child.val += x

res = []
for node in nodes:
    res.append(str(node.val))
print(" ".join(res))

Fixed submission:
n, q = map(int, input().split())

children_map = [None] * n
vals = [0] * n

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

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

res = []
for i in range(n):
    parent = children_map[i]
    if parent is not None:
        vals[i] += vals[parent]
    res.append(str(vals[i]))

print(" ".join(res))

Buggy python submission (verdict: Runtime Error):
n, q = map(int, input().split())

class Node:
    def __init__(self, root):
        self.root = root
        self.children = []
        self.val = 0

    def add_child(self, child_node):
        self.children.append(child_node)
        if self.root is not None:
            self.root.add_child(child_node)

nodes = [None] * n
nodes[0] = Node(None)

for i in range(1, n):
    a, b = map(int, input().split())
    a_node = nodes[a - 1]
    if nodes[b - 1] is None:
        b_node = Node(a_node)
        nodes[b - 1] = b_node
    a_node.add_child(nodes[b - 1])

for j in range(q):
    p, x = map(int, input().split())
    node = nodes[p - 1]
    node.val += x
    children = node.children
    for child in children:
        child.val += x

res = []
for node in nodes:
    res.append(str(node.val))
print(" ".join(res))

Fixed submission:
n, q = map(int, input().split())

children_map = [None] * n
vals = [0] * n

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

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

res = []
for i in range(n):
    parent = children_map[i]
    if parent is not None:
        vals[i] += vals[parent]
    res.append(str(vals[i]))

print(" ".join(res))

Buggy python submission (verdict: Runtime Error):
n, q = map(int, input().split())

class Node:
    def __init__(self, root):
        self.root = root
        self.children = []
        self.val = 0

    def add_child(self, child_node):
        self.children.append(child_node)
        if self.root is not None:
            self.root.add_child(child_node)

nodes = [None] * n
nodes[0] = Node(None)

for i in range(1, n):
    a, b = map(int, input().split())
    a_node = nodes[a - 1]
    if b - 1 not in nodes:
        b_node = Node(a_node)
        nodes[b - 1] = b_node
    a_node.add_child(nodes[b - 1])

for j in range(q):
    p, x = map(int, input().split())
    node = nodes[p - 1]
    node.val += x
    children = node.children
    for child in children:
        child.val += x

res = []
for node in nodes:
    res.append(str(node.val))
print(" ".join(res))

Fixed submission:
n, q = map(int, input().split())

children_map = [None] * n
vals = [0] * n

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

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

res = []
for i in range(n):
    parent = children_map[i]
    if parent is not None:
        vals[i] += vals[parent]
    res.append(str(vals[i]))

print(" ".join(res))

Buggy python submission (verdict: Runtime Error):
n, q = map(int, input().split())

class Node:
    def __init__(self, root):
        self.root = root
        self.children = []
        self.val = 0

    def add_child(self, child_node):
        self.children.append(child_node)
        if self.root is not None:
            self.root.add_child(child_node)

nodes = {
    1: Node(None)
}

for i in range(1, n):
    a, b = map(int, input().split())
    a_node = nodes[a]
    if b not in nodes:
        b_node = Node(a_node)
        nodes[b] = b_node
    a_node.add_child(nodes[b])

for j in range(q):
    p, x = map(int, input().split())
    node = nodes[p]
    node.val += x
    children = node.children
    for child in children:
        child.val += x


arr = [None] * n
for k, v in nodes.items():
    arr[int(k) - 1] = v

res = []
for item in arr:
    res.append(item.val)
print(" ".join(list(map(str, res))))

Fixed submission:
n, q = map(int, input().split())

children_map = [None] * n
vals = [0] * n

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

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

res = []
for i in range(n):
    parent = children_map[i]
    if parent is not None:
        vals[i] += vals[parent]
    res.append(str(vals[i]))

print(" ".join(res))

Buggy python submission (verdict: Runtime Error):
n, q = map(int, input().split())

class Node:
    def __init__(self, root):
        self.root = root
        self.children = []
        self.val = 0

    def add_child(self, child_node):
        self.children.append(child_node)
        if self.root is not None:
            self.root.add_child(child_node)

nodes = {
    1: Node(None)
}

for i in range(1, n):
    a, b = map(int, input().split())
    a_node = nodes[a]
    if b not in nodes:
        b_node = Node(a_node)
        nodes[b] = b_node
    a_node.add_child(nodes[b])

for j in range(q):
    p, x = map(int, input().split())
    node = nodes[p]
    node.val += x
    children = node.children
    for child in children:
        child.val += x


arr = [None] * n
for k, v in nodes.items():
    arr[int(k) - 1] = v

res = []
for item in arr:
    res.append(item.val)
print(" ".join(list(map(str, res))))

Fixed submission:
n, q = map(int, input().split())

children_map = [None] * n
vals = [0] * n

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

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

res = []
for i in range(n):
    parent = children_map[i]
    if parent is not None:
        vals[i] += vals[parent]
    res.append(str(vals[i]))

print(" ".join(res))