Buggy python submission (verdict: Time Limit Exceeded):
from queue import Queue
import sys
sys.setrecursionlimit(200005)

n, q = [int(i) for i in input().split()]

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

counter = [0] * (n+1)
for _ in range(q):
    p, x = [int(i) for i in input().split()]
    counter[p] += x

queue = Queue()
queue.put([0,1])
while not queue.empty():
    parent, node = queue.get()
    for leaf in tree[node]:
        if leaf == parent:
            continue
        counter[leaf] += counter[node]
        queue.put([node, leaf])

for counter_i in counter[1:]:
    print(counter_i, end=" ")


Fixed submission:
from collections import deque

n, q = [int(i) for i in input().split()]

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

counter = [0] * (n+1)
for _ in range(q):
    p, x = [int(i) for i in input().split()]
    counter[p] += x

queue = deque([[0,1]])
while queue:
    parent, node = queue.popleft()
    for leaf in tree[node]:
        if leaf == parent:
            continue
        counter[leaf] += counter[node]
        queue.append([node, leaf])

print(*counter[1:])

Buggy python submission (verdict: Time Limit Exceeded):

import sys
sys.setrecursionlimit(200005)

n, q = [int(i) for i in input().split()]

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

counter = [0] * (n+1)
for _ in range(q):
    p, x = [int(i) for i in input().split()]
    counter[p] += x

que = [[0,1]]
while len(que) > 0:
    parent, node = que.pop(0)
    for leaf in tree[node]:
        if leaf == parent:
            continue
        counter[leaf] += counter[node]
        que.append([node, leaf])

for counter_i in counter[1:]:
    print(counter_i, end=" ")


Fixed submission:
from collections import deque

n, q = [int(i) for i in input().split()]

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

counter = [0] * (n+1)
for _ in range(q):
    p, x = [int(i) for i in input().split()]
    counter[p] += x

queue = deque([[0,1]])
while queue:
    parent, node = queue.popleft()
    for leaf in tree[node]:
        if leaf == parent:
            continue
        counter[leaf] += counter[node]
        queue.append([node, leaf])

print(*counter[1:])

Buggy python submission (verdict: Time Limit Exceeded):

import sys
sys.setrecursionlimit(200005)

n, q = [int(i) for i in input().split()]

ab = []
for i in range(n-1):
    ab.append([int(i) for i in input().split()])

px = []
for i in range(q):
    px.append([int(i) for i in input().split()])

graph = [[] for _ in range(n+1)]
for a, b in ab:
    graph[a].append(b)
    graph[b].append(a)

counter = [0] * (n+1)

for p, x in px:
    counter[p] += x

def count(node, parent=0):
    for leaf in graph[node]:
        if leaf == parent:
            continue
        counter[leaf] += counter[node]
        count(leaf, node)

count(1)

for counter_i in counter[1:]:
    print(counter_i, end=" ")


Fixed submission:
from collections import deque

n, q = [int(i) for i in input().split()]

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

counter = [0] * (n+1)
for _ in range(q):
    p, x = [int(i) for i in input().split()]
    counter[p] += x

queue = deque([[0,1]])
while queue:
    parent, node = queue.popleft()
    for leaf in tree[node]:
        if leaf == parent:
            continue
        counter[leaf] += counter[node]
        queue.append([node, leaf])

print(*counter[1:])

Buggy python submission (verdict: Runtime Error):

n, q = [int(i) for i in input().split()]

ab = []
for i in range(n-1):
    ab.append([int(i) for i in input().split()])

px = []
for i in range(q):
    px.append([int(i) for i in input().split()])

graph = [[] for _ in range(n+1)]
for a, b in ab:
    graph[a].append(b)
    graph[b].append(a)

counter = [0] * (n+1)

for p, x in px:
    counter[p] += x

def count(node, parent=0):
    for leaf in graph[node]:
        if leaf == parent:
            continue
        counter[leaf] += counter[node]
        count(leaf, node)

count(1)

for counter_i in counter[1:]:
    print(counter_i, end=" ")


Fixed submission:
from collections import deque

n, q = [int(i) for i in input().split()]

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

counter = [0] * (n+1)
for _ in range(q):
    p, x = [int(i) for i in input().split()]
    counter[p] += x

queue = deque([[0,1]])
while queue:
    parent, node = queue.popleft()
    for leaf in tree[node]:
        if leaf == parent:
            continue
        counter[leaf] += counter[node]
        queue.append([node, leaf])

print(*counter[1:])

Buggy python submission (verdict: Runtime Error):


n, q = [int(i) for i in input().split()]

ab = []
for i in range(n-1):
    ab.append([int(i) for i in input().split()])

px = []
for i in range(q):
    px.append([int(i) for i in input().split()])

tree = {}
for a, b in ab:
    if a in tree.keys():
        tree[a].append(b)
    else:
        tree[a] = [b]

counter = [0] * (n+1)

for p, x in px:
    counter[p] += x

def count(node):
    if node in tree.keys():
        for leaf in tree[node]:
            counter[leaf] += counter[node]
            count(leaf)

count(1)

for counter_i in counter[1:]:
    print(counter_i, end=" ")


Fixed submission:
from collections import deque

n, q = [int(i) for i in input().split()]

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

counter = [0] * (n+1)
for _ in range(q):
    p, x = [int(i) for i in input().split()]
    counter[p] += x

queue = deque([[0,1]])
while queue:
    parent, node = queue.popleft()
    for leaf in tree[node]:
        if leaf == parent:
            continue
        counter[leaf] += counter[node]
        queue.append([node, leaf])

print(*counter[1:])

Buggy python submission (verdict: Runtime Error):


n, q = [int(i) for i in input().split()]

ab = []
for i in range(n-1):
    ab.append([int(i) for i in input().split()])

px = []
for i in range(q):
    px.append([int(i) for i in input().split()])

tree = {}
for a, b in ab:
    if a in tree.keys():
        tree[a].append(b)
    else:
        tree[a] = [b]

counter = [0] * (n+1)

def count(p, x):
    counter[p] += x
    if p in tree.keys():
        for leaf in tree[p]:
            count(leaf, x)

for p, x in px:
    count(p, x)

for counter_i in counter[1:]:
    print(counter_i, end=" ")


Fixed submission:
from collections import deque

n, q = [int(i) for i in input().split()]

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

counter = [0] * (n+1)
for _ in range(q):
    p, x = [int(i) for i in input().split()]
    counter[p] += x

queue = deque([[0,1]])
while queue:
    parent, node = queue.popleft()
    for leaf in tree[node]:
        if leaf == parent:
            continue
        counter[leaf] += counter[node]
        queue.append([node, leaf])

print(*counter[1:])