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

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

tree = [[] for _ in range(n)]
edge = collections.deque(edge)
flag = [False] * n
flag[0] = True
while len(edge) != 0:
    a, b = edge.popleft()
    if flag[a - 1]:
        tree[a - 1].append(b - 1)
        flag[b - 1] = True
    elif flag[b - 1]:
        tree[b - 1].append(a - 1)
        flag[a - 1] = True
    else:
        edge.append((a, b))

que = collections.deque([0])
while len(que) != 0:
    i = que.popleft()
    for j in tree[i]:
        counter[j] += counter[i]
        que.append(j)

print(' '.join([str(c) for c in counter]))

Fixed submission:
import collections

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

tree = [[] for _ in range(n)]
edge = collections.deque(edge)
while len(edge) != 0:
    a, b = edge.popleft()
    tree[a - 1].append(b - 1)
    tree[b - 1].append(a - 1)

que = collections.deque([0])
flag = [False] * n
while len(que) != 0:
    i = que.popleft()
    flag[i] = True
    for j in tree[i]:
        if flag[j]: continue
        counter[j] += counter[i]
        que.append(j)

print(' '.join([str(c) for c in counter]))

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

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

tree = [[] for _ in range(n)]
edge.sort()
edge = collections.deque(edge)
flag = [False] * n
flag[0] = True
while len(edge) != 0:
    a, b = edge.popleft()
    if flag[a - 1]:
        tree[a - 1].append(b - 1)
        flag[b - 1] = True
    elif flag[b - 1]:
        tree[b - 1].append(a - 1)
        flag[a - 1] = True
    else:
        edge.append((a, b))

que = collections.deque([0])
while len(que) != 0:
    i = que.popleft()
    counter[i] += p[i]
    for j in tree[i]:
        counter[j] = counter[i]
        que.append(j)

print(' '.join([str(c) for c in counter]))

Fixed submission:
import collections

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

tree = [[] for _ in range(n)]
edge = collections.deque(edge)
while len(edge) != 0:
    a, b = edge.popleft()
    tree[a - 1].append(b - 1)
    tree[b - 1].append(a - 1)

que = collections.deque([0])
flag = [False] * n
while len(que) != 0:
    i = que.popleft()
    flag[i] = True
    for j in tree[i]:
        if flag[j]: continue
        counter[j] += counter[i]
        que.append(j)

print(' '.join([str(c) for c in counter]))

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

n, q = map(int, input().split())
edge = [tuple(map(int, input().split())) for _ in range(n - 1)]
query = [tuple(map(int, input().split())) for _ in range(q)]

tree = [[] for _ in range(n)]
edge.sort()
edge = collections.deque(edge)
flag = [False] * n
flag[0] = True
while len(edge) != 0:
    a, b = edge.popleft()
    if flag[a - 1]:
        tree[a - 1].append(b - 1)
        flag[b - 1] = True
    elif flag[b - 1]:
        tree[b - 1].append(a - 1)
        flag[a - 1] = True
    else:
        edge.append((a, b))

p = [0] * n
for x, y in query:
    p[x - 1] += y
counter = [0] * n

que = collections.deque([0])
while len(que) != 0:
    i = que.popleft()
    counter[i] += p[i]
    for j in tree[i]:
        counter[j] = counter[i]
        que.append(j)

print(' '.join([str(c) for c in counter]))

Fixed submission:
import collections

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

tree = [[] for _ in range(n)]
edge = collections.deque(edge)
while len(edge) != 0:
    a, b = edge.popleft()
    tree[a - 1].append(b - 1)
    tree[b - 1].append(a - 1)

que = collections.deque([0])
flag = [False] * n
while len(que) != 0:
    i = que.popleft()
    flag[i] = True
    for j in tree[i]:
        if flag[j]: continue
        counter[j] += counter[i]
        que.append(j)

print(' '.join([str(c) for c in counter]))

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

n, q = map(int, input().split())
edge = collections.deque([tuple(map(int, input().split())) for _ in range(n - 1)])
query = [tuple(map(int, input().split())) for _ in range(q)]

tree = [[] for _ in range(n)]
flag = [False] * n
flag[0] = True
while len(edge) != 0:
    a, b = edge.popleft()
    if flag[a - 1]:
        tree[a - 1].append(b - 1)
        flag[b - 1] = True
    elif flag[b - 1]:
        tree[b - 1].append(a - 1)
        flag[a - 1] = True
    else:
        edge.append((a, b))

p = [0] * n
for x, y in query:
    p[x - 1] += y
counter = [0] * n

que = collections.deque([0])
while len(que) != 0:
    i = que.popleft()
    counter[i] += p[i]
    for j in tree[i]:
        counter[j] = counter[i]
        que.append(j)

print(' '.join([str(c) for c in counter]))

Fixed submission:
import collections

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

tree = [[] for _ in range(n)]
edge = collections.deque(edge)
while len(edge) != 0:
    a, b = edge.popleft()
    tree[a - 1].append(b - 1)
    tree[b - 1].append(a - 1)

que = collections.deque([0])
flag = [False] * n
while len(que) != 0:
    i = que.popleft()
    flag[i] = True
    for j in tree[i]:
        if flag[j]: continue
        counter[j] += counter[i]
        que.append(j)

print(' '.join([str(c) for c in counter]))

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

n, q = map(int, input().split())
edge = collections.deque([tuple(map(int, input().split())) for _ in range(n - 1)])
query = [tuple(map(int, input().split())) for _ in range(q)]

tree = [[] for _ in range(n)]
flag = [False] * n
flag[0] = True
while len(edge) != 0:
    a, b = edge.popleft()
    if flag[a - 1]:
        tree[a - 1].append(b - 1)
        flag[b - 1] = True
    elif flag[b - 1]:
        tree[b - 1].append(a - 1)
        flag[a - 1] = True
    else:
        edge.append((a, b))

p = [0] * n
for x, y in query:
    p[x - 1] += y
counter = [0] * n

que = collections.deque([0])
while len(que) != 0:
    i = que.popleft()
    counter[i] += p[i]
    for j in tree[i]:
        counter[j] = counter[i]
        que.append(j)

print(' '.join([str(c) for c in counter]))

Fixed submission:
import collections

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

tree = [[] for _ in range(n)]
edge = collections.deque(edge)
while len(edge) != 0:
    a, b = edge.popleft()
    tree[a - 1].append(b - 1)
    tree[b - 1].append(a - 1)

que = collections.deque([0])
flag = [False] * n
while len(que) != 0:
    i = que.popleft()
    flag[i] = True
    for j in tree[i]:
        if flag[j]: continue
        counter[j] += counter[i]
        que.append(j)

print(' '.join([str(c) for c in counter]))

Buggy python submission (verdict: Runtime Error):
import collections

n, q = map(int, input().split())
edge = collections.deque([tuple(map(int, input().split())) for _ in range(n - 1)])
query = [tuple(map(int, input().split())) for _ in range(q)]

tree = [[] for _ in range(n)]
flag = [False] * n
flag[0] = True
while len(edge) != 0:
    a, b = edge.popleft()
    a, b = a - 1, b - 1
    if flag[a] or flag[b]:
        edge.append((a, b))
        continue
    if flag[a]:
        tree[a].append(b)
    else:
        tree[b].append(b)

p = [0] * n
for x, y in query:
    p[x - 1] += y
counter = [0] * n

que = collections.deque([0])
while len(que) != 0:
    i = que.popleft()
    counter[i] += p[i]
    for j in tree[i]:
        counter[j] = counter[i]
        que.append(j)

print(' '.join([str(c) for c in counter]))

Fixed submission:
import collections

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

tree = [[] for _ in range(n)]
edge = collections.deque(edge)
while len(edge) != 0:
    a, b = edge.popleft()
    tree[a - 1].append(b - 1)
    tree[b - 1].append(a - 1)

que = collections.deque([0])
flag = [False] * n
while len(que) != 0:
    i = que.popleft()
    flag[i] = True
    for j in tree[i]:
        if flag[j]: continue
        counter[j] += counter[i]
        que.append(j)

print(' '.join([str(c) for c in counter]))

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 5)

n, q = map(int, input().split())
edge = [tuple(map(int, input().split())) for _ in range(n - 1)]
query = [tuple(map(int, input().split())) for _ in range(q)]

tree = [[] for _ in range(n)]
for a, b in edge:
    tree[a - 1].append(b - 1)
p = [0] * n
for x, y in query:
    p[x - 1] += y

counter = [0] * n

def solve(i=0, c=0):
    c += p[i]
    counter[i] = c
    for j in tree[i]:
        solve(j, c)
    return

solve()
for c in counter:
    print(c, end=' ')

Fixed submission:
import collections

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

tree = [[] for _ in range(n)]
edge = collections.deque(edge)
while len(edge) != 0:
    a, b = edge.popleft()
    tree[a - 1].append(b - 1)
    tree[b - 1].append(a - 1)

que = collections.deque([0])
flag = [False] * n
while len(que) != 0:
    i = que.popleft()
    flag[i] = True
    for j in tree[i]:
        if flag[j]: continue
        counter[j] += counter[i]
        que.append(j)

print(' '.join([str(c) for c in counter]))

Buggy python submission (verdict: Runtime Error):
n, q = map(int, input().split())
edge = [tuple(map(int, input().split())) for _ in range(n - 1)]
query = [tuple(map(int, input().split())) for _ in range(q)]

tree = [[] for _ in range(n)]
for a, b in edge:
    tree[a - 1].append(b - 1)
p = [0] * n
for x, y in query:
    p[x - 1] += y

counter = [0] * n

def solve(i=0, c=0):
    c += p[i]
    counter[i] = c
    for j in tree[i]:
        solve(j, c)
    return

solve()
for c in counter:
    print(c, end=' ')
print()

Fixed submission:
import collections

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

tree = [[] for _ in range(n)]
edge = collections.deque(edge)
while len(edge) != 0:
    a, b = edge.popleft()
    tree[a - 1].append(b - 1)
    tree[b - 1].append(a - 1)

que = collections.deque([0])
flag = [False] * n
while len(que) != 0:
    i = que.popleft()
    flag[i] = True
    for j in tree[i]:
        if flag[j]: continue
        counter[j] += counter[i]
        que.append(j)

print(' '.join([str(c) for c in counter]))