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

input = sys.stdin.readline

n, q = map(int, input().split())
es = [[] for _ in range(n + 1)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    es[a].append(b)
    es[b].append(a)

ps = [0] * (n + 1)
for _ in range(q):
    p, v = map(int, input().split())
    ps[p] += v

visited = [False] * (n + 1)
visited[0] = True
visited[1] = True
while not all(visited):
    for a in range(1, n + 1):
        if not visited[a]:
            continue
        for b in es[a]:
            if not visited[b]:
                ps[b] += ps[a]
            visited[b] = True
print(*ps[1:])

Fixed submission:
import collections
import sys

input = sys.stdin.readline

n, q = map(int, input().split())
es = [[] for _ in range(n + 1)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    es[a].append(b)
    es[b].append(a)

ps = [0] * (n + 1)
for _ in range(q):
    p, v = map(int, input().split())
    ps[p] += v

remaining = collections.deque([[0, 1]])
while len(remaining) > 0:
    a, b = remaining.popleft()
    ps[b] += ps[a]
    for c in es[b]:
        if c != a:
            remaining.append([b, c])
print(*ps[1:])

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

input = sys.stdin.readline

n, q = map(int, input().split())
es = [[] for _ in range(n + 1)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    es[a].append(b)
    es[b].append(a)

ps = [0] * (n + 1)
for _ in range(q):
    p, v = map(int, input().split())
    ps[p] += v

visited = [False] * (n + 1)
visited[0] = True
visited[1] = True
while not all(visited):
    for a in range(1, n + 1):
        if not visited[a]:
            continue
        for b in es[a]:
            if not visited[b]:
                ps[b] += ps[a]
            visited[b] = True
print(*ps[1:])

Fixed submission:
import collections
import sys

input = sys.stdin.readline

n, q = map(int, input().split())
es = [[] for _ in range(n + 1)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    es[a].append(b)
    es[b].append(a)

ps = [0] * (n + 1)
for _ in range(q):
    p, v = map(int, input().split())
    ps[p] += v

remaining = collections.deque([[0, 1]])
while len(remaining) > 0:
    a, b = remaining.popleft()
    ps[b] += ps[a]
    for c in es[b]:
        if c != a:
            remaining.append([b, c])
print(*ps[1:])

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

input = sys.stdin.readline

n, q = map(int, input().split())
ls = collections.deque([list(map(int, input().split())) for _ in range(n - 1)])

ps = [0] * (n + 1)
for _ in range(q):
    p, v = map(int, input().split())
    ps[p] += v

levels = [-1] * (n + 1)
levels[1] = 0
while len(ls) > 0:
    a, b = ls.popleft()
    la = levels[a]
    lb = levels[b]
    if la >= 0:
        levels[b] = la + 1
        ps[b] += ps[a]
    elif lb >= 0:
        levels[a] = lb + 1
        ps[a] += ps[b]
    else:
        ls.append([a, b])

print(*ps[1:])

Fixed submission:
import collections
import sys

input = sys.stdin.readline

n, q = map(int, input().split())
es = [[] for _ in range(n + 1)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    es[a].append(b)
    es[b].append(a)

ps = [0] * (n + 1)
for _ in range(q):
    p, v = map(int, input().split())
    ps[p] += v

remaining = collections.deque([[0, 1]])
while len(remaining) > 0:
    a, b = remaining.popleft()
    ps[b] += ps[a]
    for c in es[b]:
        if c != a:
            remaining.append([b, c])
print(*ps[1:])

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

n, q = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(n - 1)]
ls.sort(key=lambda x: x[0])
ls = collections.deque(ls)

ps = [0] * (n + 1)
for _ in range(q):
    p, v = map(int, input().split())
    ps[p] += v

levels = [-1] * (n + 1)
levels[1] = 0
es = []
while len(ls) > 0:
    e = ls.popleft()
    l0 = levels[e[0]]
    l1 = levels[e[1]]
    if l0 >= 0:
        levels[e[1]] = l0 + 1
        es.append(e + [l0])
    elif l1 >= 0:
        levels[e[0]] = l1 + 1
        es.append(e[::-1] + [l1])
    else:
        ls.append(e)
es.sort(key=lambda x: x[2])

for a, b, _ in es:
    ps[b] += ps[a]
print(*ps[1:])


Fixed submission:
import collections
import sys

input = sys.stdin.readline

n, q = map(int, input().split())
es = [[] for _ in range(n + 1)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    es[a].append(b)
    es[b].append(a)

ps = [0] * (n + 1)
for _ in range(q):
    p, v = map(int, input().split())
    ps[p] += v

remaining = collections.deque([[0, 1]])
while len(remaining) > 0:
    a, b = remaining.popleft()
    ps[b] += ps[a]
    for c in es[b]:
        if c != a:
            remaining.append([b, c])
print(*ps[1:])

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

n, q = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(n - 1)]
ls.sort(key=lambda x: x[0])
ls = collections.deque(ls)

ps = [0] * (n + 1)
for _ in range(q):
    p, v = map(int, input().split())
    ps[p] += v

levels = [-1] * (n + 1)
levels[1] = 0
es = []
while len(ls) > 0:
    e = ls.popleft()
    l0 = levels[e[0]]
    l1 = levels[e[1]]
    if l0 >= 0:
        levels[e[1]] = l0 + 1
        es.append(e + [l0])
    elif l1 >= 0:
        levels[e[0]] = l1 + 1
        es.append(e[::-1] + [l1])
    else:
        ls.append(e)
es.sort(key=lambda x: x[2])

for a, b, _ in es:
    ps[b] += ps[a]
print(*ps[1:])


Fixed submission:
import collections
import sys

input = sys.stdin.readline

n, q = map(int, input().split())
es = [[] for _ in range(n + 1)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    es[a].append(b)
    es[b].append(a)

ps = [0] * (n + 1)
for _ in range(q):
    p, v = map(int, input().split())
    ps[p] += v

remaining = collections.deque([[0, 1]])
while len(remaining) > 0:
    a, b = remaining.popleft()
    ps[b] += ps[a]
    for c in es[b]:
        if c != a:
            remaining.append([b, c])
print(*ps[1:])

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

    def add_value(self, value):
        if self.index > 0:
            self.value += value
            for child in self.children:
                child.add_value(value)


class Tree:
    def __init__(self):
        self.node_indices = {}
        self.nodes = []

        self.add_node(1, 0)

    def add_node(self, index, parent_index):
        node = Node(index, parent_index)
        self.node_indices[index] = len(self.nodes)
        self.nodes.append(node)

        if index > 1:
            parent_node = self.nodes[self.node_indices[parent_index]]
            parent_node.children.append(node)

    def add_value(self, index, value):
        node = self.nodes[self.node_indices[index]]
        node.add_value(value)


def main():
    n, q = map(int, input().split())

    tree = Tree()
    for _ in range(n - 1):
        parent_index, child_index = map(int, input().split())
        tree.add_node(child_index, parent_index)

    for _ in range(q):
        index, value = map(int, input().split())
        tree.add_value(index, value)

    res = []
    for index in range(1, n + 1):
        node = tree.nodes[tree.node_indices[index]]
        res.append(node.value)
    print(' '.join(map(str, res)))


if __name__ == '__main__':
    main()

Fixed submission:
import collections
import sys

input = sys.stdin.readline

n, q = map(int, input().split())
es = [[] for _ in range(n + 1)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    es[a].append(b)
    es[b].append(a)

ps = [0] * (n + 1)
for _ in range(q):
    p, v = map(int, input().split())
    ps[p] += v

remaining = collections.deque([[0, 1]])
while len(remaining) > 0:
    a, b = remaining.popleft()
    ps[b] += ps[a]
    for c in es[b]:
        if c != a:
            remaining.append([b, c])
print(*ps[1:])

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

    def add_value(self, value):
        if self.index > 0:
            self.value += value
            for child in self.children:
                child.add_value(value)


class Tree:
    def __init__(self):
        self.node_indices = {}
        self.nodes = []

        self.add_node(1, 0)

    def add_node(self, index, parent_index):
        node = Node(index, parent_index)
        self.node_indices[index] = len(self.nodes)
        self.nodes.append(node)

        if index > 1:
            parent_node = self.nodes[self.node_indices[parent_index]]
            parent_node.children.append(node)

    def add_value(self, index, value):
        node = self.nodes[self.node_indices[index]]
        node.add_value(value)


def main():
    n, q = map(int, input().split())

    tree = Tree()
    for _ in range(n - 1):
        parent_index, child_index = map(int, input().split())
        tree.add_node(child_index, parent_index)

    for _ in range(q):
        index, value = map(int, input().split())
        print(index, value)
        tree.add_value(index, value)

    res = []
    for index in range(1, n + 1):
        node = tree.nodes[tree.node_indices[index]]
        res.append(node.value)
    print(' '.join(map(str, res)))


if __name__ == '__main__':
    main()

Fixed submission:
import collections
import sys

input = sys.stdin.readline

n, q = map(int, input().split())
es = [[] for _ in range(n + 1)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    es[a].append(b)
    es[b].append(a)

ps = [0] * (n + 1)
for _ in range(q):
    p, v = map(int, input().split())
    ps[p] += v

remaining = collections.deque([[0, 1]])
while len(remaining) > 0:
    a, b = remaining.popleft()
    ps[b] += ps[a]
    for c in es[b]:
        if c != a:
            remaining.append([b, c])
print(*ps[1:])

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

    def add_value(self, value):
        if self.index > 0:
            self.value += value
            for child in self.children:
                child.add_value(value)


class Tree:
    def __init__(self):
        self.node_indices = {}
        self.nodes = []

        self.add_node(1, 0)

    def add_node(self, index, parent_index):
        node = Node(index, parent_index)
        self.node_indices[index] = len(self.nodes)
        self.nodes.append(node)

        if index > 1:
            parent_node = self.nodes[self.node_indices[parent_index]]
            parent_node.children.append(node)

    def add_value(self, index, value):
        node = self.nodes[self.node_indices[index]]
        node.add_value(value)


def main():
    n, q = map(int, input().split())

    tree = Tree()
    for _ in range(n - 1):
        parent_index, child_index = map(int, input().split())
        tree.add_node(child_index, parent_index)

    for _ in range(q):
        index, value = map(int, input().split())
        print(index, value)
        tree.add_value(index, value)

    res = []
    for index in range(1, n + 1):
        node = tree.nodes[tree.node_indices[index]]
        res.append(node.value)
    print(' '.join(map(str, res)))


if __name__ == '__main__':
    main()

Fixed submission:
import collections
import sys

input = sys.stdin.readline

n, q = map(int, input().split())
es = [[] for _ in range(n + 1)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    es[a].append(b)
    es[b].append(a)

ps = [0] * (n + 1)
for _ in range(q):
    p, v = map(int, input().split())
    ps[p] += v

remaining = collections.deque([[0, 1]])
while len(remaining) > 0:
    a, b = remaining.popleft()
    ps[b] += ps[a]
    for c in es[b]:
        if c != a:
            remaining.append([b, c])
print(*ps[1:])