Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N, Q = [int(x) for x in input().strip().split()]
res = [0 for _ in range(N)]
tree = [[] for _ in range(N)]
for n in range(N-1):
    a, b = [int(x) for x in input().strip().split()]
    tree[a-1].append(b)

for q in range(Q):
    p, x = [int(x) for x in input().strip().split()]
    res[p-1] += x

def f(n, c):
    res[n-1] += c
    if len(tree[n-1])!=0:
        for num in tree[n-1]:
            f(num, res[n-1])

f(1, 0)
print(*res)

Fixed submission:
import sys
from collections import deque
input = sys.stdin.readline

N, Q = [int(x) for x in input().strip().split()]
res = [0 for _ in range(N)]
tree = [[] for _ in range(N)]
for n in range(N-1):
    a, b = [int(x) for x in input().strip().split()]
    tree[a-1].append(b)

for q in range(Q):
    p, x = [int(x) for x in input().strip().split()]
    res[p-1] += x

q = deque([1])
cq = deque([0])
while q:
    n = q.popleft()
    c = cq.popleft()
    res[n-1] += c
    if len(tree[n-1])!=0:
        for num in tree[n-1]:
            q.append(num)
            cq.append(res[n-1])

print(*res)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N, Q = [int(x) for x in input().strip().split()]
res = [0 for _ in range(N)]
tree = [[] for _ in range(N)]
for n in range(N-1):
    a, b = [int(x) for x in input().strip().split()]
    tree[a-1].append(b)

for q in range(Q):
    p, x = [int(x) for x in input().strip().split()]
    res[p-1] += x

def f(n, c):
    res[n-1] += c
    if len(tree[n-1])!=0:
        for num in tree[n-1]:
            f(num, res[n-1])

f(1, 0)
print(*res)

Fixed submission:
import sys
from collections import deque
input = sys.stdin.readline

N, Q = [int(x) for x in input().strip().split()]
res = [0 for _ in range(N)]
tree = [[] for _ in range(N)]
for n in range(N-1):
    a, b = [int(x) for x in input().strip().split()]
    tree[a-1].append(b)

for q in range(Q):
    p, x = [int(x) for x in input().strip().split()]
    res[p-1] += x

q = deque([1])
cq = deque([0])
while q:
    n = q.popleft()
    c = cq.popleft()
    res[n-1] += c
    if len(tree[n-1])!=0:
        for num in tree[n-1]:
            q.append(num)
            cq.append(res[n-1])

print(*res)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N, Q = [int(x) for x in input().strip().split()]
res = [0 for _ in range(N)]
tree = {}
for n in range(N-1):
    a, b = [int(x) for x in input().strip().split()]
    tree[a] = tree.setdefault(a, []) + [b]

for q in range(Q):
    p, x = [int(x) for x in input().strip().split()]
    res[p-1] += x

def f(n, c):
    res[n-1] += c
    if n in tree:
        for num in tree[n]:
            f(num, res[n-1])

f(1, 0)
print(*res)

Fixed submission:
import sys
from collections import deque
input = sys.stdin.readline

N, Q = [int(x) for x in input().strip().split()]
res = [0 for _ in range(N)]
tree = [[] for _ in range(N)]
for n in range(N-1):
    a, b = [int(x) for x in input().strip().split()]
    tree[a-1].append(b)

for q in range(Q):
    p, x = [int(x) for x in input().strip().split()]
    res[p-1] += x

q = deque([1])
cq = deque([0])
while q:
    n = q.popleft()
    c = cq.popleft()
    res[n-1] += c
    if len(tree[n-1])!=0:
        for num in tree[n-1]:
            q.append(num)
            cq.append(res[n-1])

print(*res)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N, Q = [int(x) for x in input().strip().split()]
res = [0 for _ in range(N)]
tree = {}
for n in range(N-1):
    a, b = [int(x) for x in input().strip().split()]
    tree[a] = tree.setdefault(a, []) + [b]

for q in range(Q):
    p, x = [int(x) for x in input().strip().split()]
    res[p-1] += x

def f(n, c):
    res[n-1] += c
    if n in tree:
        for num in tree[n]:
            f(num, res[n-1])

f(1, 0)
print(*res)

Fixed submission:
import sys
from collections import deque
input = sys.stdin.readline

N, Q = [int(x) for x in input().strip().split()]
res = [0 for _ in range(N)]
tree = [[] for _ in range(N)]
for n in range(N-1):
    a, b = [int(x) for x in input().strip().split()]
    tree[a-1].append(b)

for q in range(Q):
    p, x = [int(x) for x in input().strip().split()]
    res[p-1] += x

q = deque([1])
cq = deque([0])
while q:
    n = q.popleft()
    c = cq.popleft()
    res[n-1] += c
    if len(tree[n-1])!=0:
        for num in tree[n-1]:
            q.append(num)
            cq.append(res[n-1])

print(*res)