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

ct = [0] * (n + 1)
target = {i: [i] for i in range(n + 1)}

for _ in range(n - 1):
    a, b = map(int, input().split())
    for k in target:
        if a in target[k]:
            target[k].append(b)

for _ in range(q):
    p, q = map(int, input().split())
    t = target[p]
    for ti in t:
        ct[ti] += q

print(*ct[1:])

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

ct = [0] * (n + 1)
e = [[] for _ in range(n + 1)]

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

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

target = [1]
while len(target):
    t = target.pop()
    ct[t] += qs[t]
    for nt in e[t]:
        target.append(nt)
        ct[nt] += ct[t]

print(*ct[1:])

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

ct = [0] * (n + 1)
target = [[i] for i in range(n + 1)]

for _ in range(n - 1):
    a, b = map(int, input().split())
    for t in target:
        if a in t:
            t.append(b)

for _ in range(q):
    p, q = map(int, input().split())
    t = target[p]
    for ti in t:
        ct[ti] += q

print(*ct[1:])

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

ct = [0] * (n + 1)
e = [[] for _ in range(n + 1)]

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

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

target = [1]
while len(target):
    t = target.pop()
    ct[t] += qs[t]
    for nt in e[t]:
        target.append(nt)
        ct[nt] += ct[t]

print(*ct[1:])

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

ct = [0] * (n + 1)
e = [[] for _ in range(n + 1)]
c = {}

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

for _ in range(q):
    p, q = map(int, input().split())
    target = c.get(p)
    if target is None:
        tmp = [p]
        target = []
        while len(tmp):
            t = tmp.pop()
            target.append(t)
            for nt in e[t]:
                tmp.append(nt)
        c[p] = target
    for t in target:
        ct[t] += q

print(*ct[1:])

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

ct = [0] * (n + 1)
e = [[] for _ in range(n + 1)]

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

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

target = [1]
while len(target):
    t = target.pop()
    ct[t] += qs[t]
    for nt in e[t]:
        target.append(nt)
        ct[nt] += ct[t]

print(*ct[1:])

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

ct = [0] * (n + 1)
e = [[] for _ in range(n + 1)]

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

for _ in range(q):
    p, q = map(int, input().split())
    target = [p]
    while len(target):
        t = target.pop()
        ct[t] += q
        for nt in e[t]:
            target.append(nt)

print(*ct[1:])


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

ct = [0] * (n + 1)
e = [[] for _ in range(n + 1)]

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

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

target = [1]
while len(target):
    t = target.pop()
    ct[t] += qs[t]
    for nt in e[t]:
        target.append(nt)
        ct[nt] += ct[t]

print(*ct[1:])