Buggy python submission (verdict: Time Limit Exceeded):
from queue import *
from sys import stdin
input = stdin.readline

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

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

unused = [1]*n
que = Queue()
que.put(0)
while que.qsize():
    m = que.get()
    unused[m] = 0
    for v in link[m]:
        if unused[v]:
            weight[v] += weight[m]
            que.put(v)
print(*weight)

Fixed submission:
from sys import stdin
n, q = map(int, input().split())
cnt = [0]*n
root = [[] for i in range(n)]

for i in range(n-1):
    a, b = map(int, stdin.readline().split())
    root[a-1].append(b-1)

for i in range(q):
    p, x = map(int, stdin.readline().split())
    cnt[p-1] += x

tmparr = [0]
while tmparr:
    tmpi = tmparr.pop()
    for i in root[tmpi]:
        cnt[i] += cnt[tmpi]
    tmparr += root[tmpi]
print(*cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
n, q = map(int, input().split())
cnt = [0]*n
root = [[] for i in range(n)]

for i in range(n-1):
    a, b = map(int, stdin.readline().split())
    root[a-1].append(b-1)

for i in range(q):
    p, x = map(int, stdin.readline().split())

    tmpi = p-1
    tmparr = [tmpi]
    while tmparr:
        tmpi = tmparr.pop()
        cnt[tmpi] += x
        tmparr += root[tmpi]
print(*cnt)

Fixed submission:
from sys import stdin
n, q = map(int, input().split())
cnt = [0]*n
root = [[] for i in range(n)]

for i in range(n-1):
    a, b = map(int, stdin.readline().split())
    root[a-1].append(b-1)

for i in range(q):
    p, x = map(int, stdin.readline().split())
    cnt[p-1] += x

tmparr = [0]
while tmparr:
    tmpi = tmparr.pop()
    for i in root[tmpi]:
        cnt[i] += cnt[tmpi]
    tmparr += root[tmpi]
print(*cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
cnt = [0]*n
root = [[] for i in range(n)]

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

for i in range(q):
    p, x = map(int, input().split())
    cnt[p-1] += x

tmparr = [0]
while tmparr:
    tmpi = tmparr.pop(0)
    for i in root[tmpi]:
        cnt[i] += cnt[tmpi]
    tmparr += root[tmpi]
print(*cnt)

Fixed submission:
from sys import stdin
n, q = map(int, input().split())
cnt = [0]*n
root = [[] for i in range(n)]

for i in range(n-1):
    a, b = map(int, stdin.readline().split())
    root[a-1].append(b-1)

for i in range(q):
    p, x = map(int, stdin.readline().split())
    cnt[p-1] += x

tmparr = [0]
while tmparr:
    tmpi = tmparr.pop()
    for i in root[tmpi]:
        cnt[i] += cnt[tmpi]
    tmparr += root[tmpi]
print(*cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
cnt = [0]*n
root = [[] for i in range(n)]

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

for i in range(q):
    p, x = map(int, input().split())

    tmpi = p-1
    tmparr = [tmpi]
    while tmparr:
        tmpi = tmparr.pop(0)
        cnt[tmpi] += x
        tmparr += root[tmpi]
print(*cnt)

Fixed submission:
from sys import stdin
n, q = map(int, input().split())
cnt = [0]*n
root = [[] for i in range(n)]

for i in range(n-1):
    a, b = map(int, stdin.readline().split())
    root[a-1].append(b-1)

for i in range(q):
    p, x = map(int, stdin.readline().split())
    cnt[p-1] += x

tmparr = [0]
while tmparr:
    tmpi = tmparr.pop()
    for i in root[tmpi]:
        cnt[i] += cnt[tmpi]
    tmparr += root[tmpi]
print(*cnt)

Buggy python submission (verdict: Time Limit Exceeded):
def roooot(arr, i):
    tmp = i
    while len(arr[i]) != 1:
        i = list(arr[i])[0]-1
        arr[tmp].add(i+1)

def pt(st):
    ret = 0
    for i in list(st):
        ret += cnt[i-1]
    print(ret, end=" ")

n, q = map(int, input().split())
cnt = [0]*n
root = [set([i+1]) for i in range(n)]

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

for i in range(q):
    p, x = map(int, input().split())
    cnt[p-1] += x

for i in root: pt(list(i))
print("")

Fixed submission:
from sys import stdin
n, q = map(int, input().split())
cnt = [0]*n
root = [[] for i in range(n)]

for i in range(n-1):
    a, b = map(int, stdin.readline().split())
    root[a-1].append(b-1)

for i in range(q):
    p, x = map(int, stdin.readline().split())
    cnt[p-1] += x

tmparr = [0]
while tmparr:
    tmpi = tmparr.pop()
    for i in root[tmpi]:
        cnt[i] += cnt[tmpi]
    tmparr += root[tmpi]
print(*cnt)

Buggy python submission (verdict: Time Limit Exceeded):
def roooot(arr, i):
    tmp = i
    while len(arr[i]) != 1:
        i = arr[i][-1]-1
        arr[tmp].append(i+1)

n, q = map(int, input().split())
cnt = [0]*n
root = [[i+1] for i in range(n)]

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

for i in range(q):
    p, x = map(int, input().split())
    for j in range(len(root)):
        if p in root[j]: cnt[j] += x
print(*cnt)

Fixed submission:
from sys import stdin
n, q = map(int, input().split())
cnt = [0]*n
root = [[] for i in range(n)]

for i in range(n-1):
    a, b = map(int, stdin.readline().split())
    root[a-1].append(b-1)

for i in range(q):
    p, x = map(int, stdin.readline().split())
    cnt[p-1] += x

tmparr = [0]
while tmparr:
    tmpi = tmparr.pop()
    for i in root[tmpi]:
        cnt[i] += cnt[tmpi]
    tmparr += root[tmpi]
print(*cnt)