Buggy python submission (verdict: Runtime Error):
import sys

input = sys.stdin.readline


class Node:
    def __init__(self, id):
        self.id = id
        self.next = []
        self.val = 0

    def set_node(self, node):
        self.next.append(node)


def add_val(node, val):
    global tree
    node.val += val
    if not node.next:
        return
    for i in node.next:
        add_val(tree[i], val)


n, q = map(int, input().split())
tree = [Node(id) for id in range(n + 1)]
query = [0 for _ in range(n + 1)]

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

for i in range(q):
    p, x = map(int, input().split())
    query[p] += x

for i in range(1, n + 1):
    val = query[i]
    if val != 0:
        add_val(tree[i], val)

print(*[tree[i].val for i in range(1, n + 1)])


Fixed submission:
import sys

input = sys.stdin.readline


class Node:
    def __init__(self, parent_id=None):
        self.val = 0
        self.parent_id = parent_id


n, q = map(int, input().split())
tree = [Node() for _ in range(n)]

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

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

for i in range(1, n):
    tree[i].val += tree[tree[i].parent_id].val

print(*[node.val for node in tree])

Buggy python submission (verdict: Runtime Error):
import sys

input = sys.stdin.readline


class Node:
    def __init__(self, id):
        self.id = id
        self.next = []
        self.val = 0

    def set_node(self, node):
        self.next.append(node)


def add_val(node, val):
    global tree
    node.val += val
    if not node.next:
        return
    for i in node.next:
        add_val(tree[i], val)


n, q = map(int, input().split())
tree = [Node(id) for id in range(n + 1)]
query = [0 for _ in range(n + 1)]

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

for i in range(q):
    p, x = map(int, input().split())
    query[p] += x

for i in range(n):
    val = query[i]
    if val != 0:
        add_val(tree[i], val)

print(*[tree[i].val for i in range(1, n + 1)])


Fixed submission:
import sys

input = sys.stdin.readline


class Node:
    def __init__(self, parent_id=None):
        self.val = 0
        self.parent_id = parent_id


n, q = map(int, input().split())
tree = [Node() for _ in range(n)]

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

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

for i in range(1, n):
    tree[i].val += tree[tree[i].parent_id].val

print(*[node.val for node in tree])

Buggy python submission (verdict: Runtime Error):
import sys

input = sys.stdin.readline


class Node:
    def __init__(self, id):
        self.id = id
        self.next = []
        self.val = 0

    def set_node(self, node):
        self.next.append(node)


def add_val(node, val):
    global tree
    node.val += val
    if not node.next:
        return
    for i in node.next:
        add_val(tree[i], val)


n, q = map(int, input().split())
tree = [Node(id) for id in range(n + 1)]

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

for i in range(q):
    p, x = map(int, input().split())
    add_val(tree[p], x)

print(*[tree[i].val for i in range(1, n + 1)])


Fixed submission:
import sys

input = sys.stdin.readline


class Node:
    def __init__(self, parent_id=None):
        self.val = 0
        self.parent_id = parent_id


n, q = map(int, input().split())
tree = [Node() for _ in range(n)]

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

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

for i in range(1, n):
    tree[i].val += tree[tree[i].parent_id].val

print(*[node.val for node in tree])

Buggy python submission (verdict: Runtime Error):
import sys

input = sys.stdin.readline


class Node:
    def __init__(self, id):
        self.id = id
        self.node1 = 0
        self.node2 = 0
        self.val = 0

    def set_node(self, node):
        if self.node1 == 0:
            self.node1 = node
        else:
            self.node2 = node


def add_val(node, val):
    global tree
    if node.id == 0:
        return
    node.val += val
    add_val(tree[node.node1], val)
    add_val(tree[node.node2], val)


n, q = map(int, input().split())
tree = [Node(id) for id in range(n + 1)]

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

for i in range(q):
    p, x = map(int, input().split())
    add_val(tree[p], x)

print(*[tree[i].val for i in range(1, n + 1)])


Fixed submission:
import sys

input = sys.stdin.readline


class Node:
    def __init__(self, parent_id=None):
        self.val = 0
        self.parent_id = parent_id


n, q = map(int, input().split())
tree = [Node() for _ in range(n)]

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

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

for i in range(1, n):
    tree[i].val += tree[tree[i].parent_id].val

print(*[node.val for node in tree])

Buggy python submission (verdict: Runtime Error):
class Node:
    def __init__(self, id):
        self.id = id
        self.node1 = 0
        self.node2 = 0
        self.val = 0

    def set_node(self, node):
        if self.node1 == 0:
            self.node1 = node
        else:
            self.node2 = node


def add_val(node, val):
    global tree
    if node.id == 0:
        return
    node.val += val
    add_val(tree[node.node1], val)
    add_val(tree[node.node2], val)


n, q = map(int, input().split())
tree = [Node(id) for id in range(n + 1)]

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

for i in range(q):
    p, x = map(int, input().split())
    add_val(tree[p], x)

print(*[tree[i].val for i in range(1, n + 1)])


Fixed submission:
import sys

input = sys.stdin.readline


class Node:
    def __init__(self, parent_id=None):
        self.val = 0
        self.parent_id = parent_id


n, q = map(int, input().split())
tree = [Node() for _ in range(n)]

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

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

for i in range(1, n):
    tree[i].val += tree[tree[i].parent_id].val

print(*[node.val for node in tree])

Buggy python submission (verdict: Runtime Error):
class Node:
    def __init__(self, id):
        self.id = id
        self.node1 = 0
        self.node2 = 0
        self.val = 0

    def set_node(self, node):
        if self.node1 == 0:
            self.node1 = node
        else:
            self.node2 = node


def add_val(node, val):
    global tree
    if node.id == 0:
        return
    node.val += val
    add_val(tree[node.node1], val)
    add_val(tree[node.node2], val)


n, q = map(int, input().split())
tree = [Node(id) for id in range(n + 1)]

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

for i in range(q):
    p, x = map(int, input().split())
    add_val(tree[p], x)

for i in range(1, n + 1):
    if i != 1:
        print(" ", end="")
    print(tree[i].val, end="")
print("")


Fixed submission:
import sys

input = sys.stdin.readline


class Node:
    def __init__(self, parent_id=None):
        self.val = 0
        self.parent_id = parent_id


n, q = map(int, input().split())
tree = [Node() for _ in range(n)]

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

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

for i in range(1, n):
    tree[i].val += tree[tree[i].parent_id].val

print(*[node.val for node in tree])