Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict, deque

d = ' '
n, q = map(int, input().split(d))

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

count = defaultdict(lambda: 0)
for _ in range(q):
    p, x = map(int, input().split(d))
    count[p] += x

ret = [0] * n
q = deque(maxlen=n)
q.append((1, 1))
while len(q) > 0:
    f, c = q.popleft()
    ret[c - 1] = count[c] + ret[f - 1]
    for n in tree[c]:
        if n != f:
            q.append((c, n))

print(*ret)


Fixed submission:
from collections import defaultdict, deque

n, q = map(int, input().split())

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

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

ret = [0] * n
q = deque(maxlen = n)
q.append((0, 0))
while len(q) > 0:
    f, c = q.popleft()
    ret[c] = count[c] + ret[f]
    for n in tree[c]:
        if n != f:
            q.append((c, n))

print(*ret)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict, deque

n, q = map(int, input().split())

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

count = defaultdict(lambda: 0)
for _ in range(q):
    p, x = map(int, input().split())
    count[p] += x

ret = [0] * n
q = deque(maxlen=n)
q.append((1, 1))
while len(q) > 0:
    f, c = q.popleft()
    ret[c - 1] = count[c] + ret[f - 1]
    for n in tree[c]:
        if n != f:
            q.append((c, n))

print(*ret)


Fixed submission:
from collections import defaultdict, deque

n, q = map(int, input().split())

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

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

ret = [0] * n
q = deque(maxlen = n)
q.append((0, 0))
while len(q) > 0:
    f, c = q.popleft()
    ret[c] = count[c] + ret[f]
    for n in tree[c]:
        if n != f:
            q.append((c, n))

print(*ret)

Buggy python submission (verdict: Runtime Error):
from queue import Queue
from collections import defaultdict

count = defaultdict(int)
tree = defaultdict(lambda: [])

n, q = map(int, input().split())
for _ in range(_q):
    p, x = map(int, input().split())
    count[p] += x
for _ in range(_n - 1):
    a, b = map(int, input().split())
    tree[a].append(b)

ret = [0] * n
q = Queue()
q.put((0, 1))
while not q.empty():
    f, c = q.get()
    ret[c - 1] = count[c] + ret[f - 1]
    for n in tree[c]:
        if n != f:
            q.put((c, n))

print(*ret)


Fixed submission:
from collections import defaultdict, deque

n, q = map(int, input().split())

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

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

ret = [0] * n
q = deque(maxlen = n)
q.append((0, 0))
while len(q) > 0:
    f, c = q.popleft()
    ret[c] = count[c] + ret[f]
    for n in tree[c]:
        if n != f:
            q.append((c, n))

print(*ret)

Buggy python submission (verdict: Runtime Error):
from queue import Queue
from collections import defaultdict

def solve(n, q, AB, PX):
    count = defaultdict(int)
    for p, x in PX:
        count[p] += x

    tree = defaultdict(lambda: [])
    for a, b in AB:
        tree[a].append(b)

    ret = [0] * n
    q = Queue()
    q.put((1, 1))
    while not q.empty():
        f, c = q.get()
        ret[c - 1] = count[c] + ret[f - 1]
        for n in tree[c]:
            if f != c:
                q.put((c, n))

    return ret

_n, _q = map(int, input().split())
_AB = [map(int, input().split()) for _ in xrange(_n - 1)]
_PX = [map(int, input().split()) for _ in xrange(_q)]
print(*solve(_n, _q, _AB, _PX))


Fixed submission:
from collections import defaultdict, deque

n, q = map(int, input().split())

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

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

ret = [0] * n
q = deque(maxlen = n)
q.append((0, 0))
while len(q) > 0:
    f, c = q.popleft()
    ret[c] = count[c] + ret[f]
    for n in tree[c]:
        if n != f:
            q.append((c, n))

print(*ret)

Buggy python submission (verdict: Time Limit Exceeded):
from queue import Queue
from collections import defaultdict

def solve(n, q, AB, PX):
    count = defaultdict(int)
    for p, x in PX:
        count[p] += x

    tree = defaultdict(lambda: [])
    for a, b in AB:
        tree[a].append(b)
        tree[b].append(a)

    ret = [0] * n
    q = Queue()
    q.put((0, 1, count[1]))
    while not q.empty():
        f, c, x = q.get()
        count[c] += count[f]
        ret[c - 1] = count[c]
        for n in tree[c]:
            if n != f:
                q.put((c, n, count[c]))

    return ret

_n, _q = map(int, input().split())
_AB = [list(map(int, input().split())) for _ in range(_n - 1)]
_PX = [list(map(int, input().split())) for _ in range(_q)]
print(*solve(_n, _q, _AB, _PX))


Fixed submission:
from collections import defaultdict, deque

n, q = map(int, input().split())

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

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

ret = [0] * n
q = deque(maxlen = n)
q.append((0, 0))
while len(q) > 0:
    f, c = q.popleft()
    ret[c] = count[c] + ret[f]
    for n in tree[c]:
        if n != f:
            q.append((c, n))

print(*ret)

Buggy python submission (verdict: Time Limit Exceeded):
from queue import Queue
from collections import defaultdict

def solve(n, q, AB, PX):
    count = defaultdict(int)
    for p, x in PX:
        count[p] += x

    tree = defaultdict(lambda: [])
    for a, b in AB:
        tree[a].append(b)
        tree[b].append(a)

    ret = [0] * n
    q = Queue()
    q.put((0, 1, count[1]))
    while not q.empty():
        f, c, x = q.get()
        count[c] += count[f]
        ret[c - 1] = count[c]
        for n in tree[c]:
            if n != f:
                q.put((c, n, count[c]))

    return ret

_n, _q = map(int, input().split())
_AB = [list(map(int, input().split())) for _ in range(_n - 1)]
_PX = [list(map(int, input().split())) for _ in range(_q)]
print(*solve(_n, _q, _AB, _PX))


Fixed submission:
from collections import defaultdict, deque

n, q = map(int, input().split())

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

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

ret = [0] * n
q = deque(maxlen = n)
q.append((0, 0))
while len(q) > 0:
    f, c = q.popleft()
    ret[c] = count[c] + ret[f]
    for n in tree[c]:
        if n != f:
            q.append((c, n))

print(*ret)