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

N, Q = map(int, input().split())

connect_dic = defaultdict(list)

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

query_weight = defaultdict(int)
for _ in range(Q):
    q, x = map(int, input().split())
    query_weight[q] += x

used = set()
dq = deque([1])
used.add(1)
ans = [0] * (N + 1)

while dq:
    node = dq.popleft()
    can = connect_dic[node]

    used.add(node)
    ans[node] += query_weight[node]

    for c in can:
        if c not in used:
            ans[c] += ans[node]
            dq.append(c)


ans = [str(w) for w in ans[1:]]
print(' '.join(ans))


Fixed submission:
from collections import deque

N, Q = map(int, input().split())

connect_lst = [[] for _ in range(N + 1)]

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

query_weight = [0] * (N + 1)
for _ in range(Q):
    q, x = map(int, input().split())
    query_weight[q] += x

used = set()
dq = deque([1])
used.add(1)
ans = [0] * (N + 1)

while dq:
    node = dq.popleft()
    can = connect_lst[node]

    used.add(node)
    ans[node] += query_weight[node]

    for c in can:
        if c not in used:
            ans[c] += ans[node]
            dq.append(c)


ans = [str(w) for w in ans[1:]]
print(' '.join(ans))

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

N, Q = map(int, input().split())

connect_dic = defaultdict(list)

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

query_weight = defaultdict(int)
for _ in range(Q):
    q, x = map(int, input().split())
    query_weight[q] += x

used = set()
dq = deque([1])
used.add(1)
ans = [0] * (N + 1)

while dq:
    node = dq.popleft()
    can = connect_dic[node]

    used.add(node)
    ans[node] += query_weight[node]

    for c in can:
        if c not in used:
            ans[c] += ans[node]
            dq.append(c)


ans = [str(w) for w in ans[1:]]
print(' '.join(ans))


Fixed submission:
from collections import deque

N, Q = map(int, input().split())

connect_lst = [[] for _ in range(N + 1)]

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

query_weight = [0] * (N + 1)
for _ in range(Q):
    q, x = map(int, input().split())
    query_weight[q] += x

used = set()
dq = deque([1])
used.add(1)
ans = [0] * (N + 1)

while dq:
    node = dq.popleft()
    can = connect_lst[node]

    used.add(node)
    ans[node] += query_weight[node]

    for c in can:
        if c not in used:
            ans[c] += ans[node]
            dq.append(c)


ans = [str(w) for w in ans[1:]]
print(' '.join(ans))

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict, deque

N, Q = map(int, input().split())

parent_child = defaultdict(list)

AB_lst = [list(map(int, input().split())) for _ in range(N - 1)]
AB_lst.sort(key=lambda x: (x[0], x[1]))

for a, b in AB_lst:
    parent_child[a].append(b)

query_weight = defaultdict(int)
for _ in range(Q):
    q, x = map(int, input().split())
    query_weight[q] += x


dq = deque([])
dq.append((1, query_weight[1]))

ans = [0] * N
while dq:
    node, w = dq.popleft()
    children = parent_child[node]

    ans[node - 1] = str(w)

    for c in children:
        dq.append((c, w + query_weight[c]))


print(' '.join(ans))



Fixed submission:
from collections import deque

N, Q = map(int, input().split())

connect_lst = [[] for _ in range(N + 1)]

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

query_weight = [0] * (N + 1)
for _ in range(Q):
    q, x = map(int, input().split())
    query_weight[q] += x

used = set()
dq = deque([1])
used.add(1)
ans = [0] * (N + 1)

while dq:
    node = dq.popleft()
    can = connect_lst[node]

    used.add(node)
    ans[node] += query_weight[node]

    for c in can:
        if c not in used:
            ans[c] += ans[node]
            dq.append(c)


ans = [str(w) for w in ans[1:]]
print(' '.join(ans))

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict, deque

N, Q = map(int, input().split())

parent_child = defaultdict(set)

for i in range(N - 1):
    a, b = map(int, input().split())
    parent_child[a].add(b)

query_weight = defaultdict(int)
for _ in range(Q):
    q, x = map(int, input().split())
    query_weight[q] += x


dq = deque([])
dq.append((1, query_weight[1]))

ans = [0] * N
while dq:
    node, w = dq.popleft()
    children = parent_child[node]

    ans[node - 1] = str(w)

    for c in children:
        dq.append((c, w + query_weight[c]))


print(' '.join(ans))


Fixed submission:
from collections import deque

N, Q = map(int, input().split())

connect_lst = [[] for _ in range(N + 1)]

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

query_weight = [0] * (N + 1)
for _ in range(Q):
    q, x = map(int, input().split())
    query_weight[q] += x

used = set()
dq = deque([1])
used.add(1)
ans = [0] * (N + 1)

while dq:
    node = dq.popleft()
    can = connect_lst[node]

    used.add(node)
    ans[node] += query_weight[node]

    for c in can:
        if c not in used:
            ans[c] += ans[node]
            dq.append(c)


ans = [str(w) for w in ans[1:]]
print(' '.join(ans))

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

N, Q = map(int, input().split())

plus_dic = defaultdict(int)
AB_lst = [list(map(int, input().split())) for _ in range(N - 1)]
AB_lst = sorted(AB_lst, key=lambda x: x[1])
PX_lst = [list(map(int, input().split())) for _ in range(Q)]

for p, x in PX_lst:
    plus_dic[p] += x

out_lst = [0] * (N + 1)
out_lst[1] = plus_dic[1]

for a, b in AB_lst:
    out_lst[b] = plus_dic[b] + out_lst[a]

print(*out_lst[1:])

Fixed submission:
from collections import deque

N, Q = map(int, input().split())

connect_lst = [[] for _ in range(N + 1)]

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

query_weight = [0] * (N + 1)
for _ in range(Q):
    q, x = map(int, input().split())
    query_weight[q] += x

used = set()
dq = deque([1])
used.add(1)
ans = [0] * (N + 1)

while dq:
    node = dq.popleft()
    can = connect_lst[node]

    used.add(node)
    ans[node] += query_weight[node]

    for c in can:
        if c not in used:
            ans[c] += ans[node]
            dq.append(c)


ans = [str(w) for w in ans[1:]]
print(' '.join(ans))