Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N,Q = (int(x) for x in input().split())
ab = [list(map(int, input().split())) for _ in range(N-1)]
px = [list(map(int, input().split())) for _ in range(Q)]
connected = [[] for _ in range(N)]
for a, b in ab:
    connected[a-1].append(b)
    connected[b-1].append(a)
counter = [0] * N
for p, x in px:
    counter[p-1] += x
ans = counter
q = deque([(1,0)])
searched = [0] * N
while q:
    a,p = q.popleft()
    if searched[a-1] == 0:
        if p != 0:
            ans[a-1] += ans[p-1]
        searched[a-1] = 1
        for child in connected[a-1]:
            q.append((child,a))
print(*ans)

Fixed submission:
from collections import deque
N,Q = (int(x) for x in input().split())
connected = [[] for _ in range(N)]
for _ in range(N-1):
    a,b = (int(x) for x in input().split())
    connected[a-1].append(b)
    connected[b-1].append(a)
counter = [0] * N
for _ in range(Q):
    p,x = (int(y) for y in input().split())
    counter[p-1] += x
ans = counter
q = deque([(1,0)])
searched = [0] * N
while q:
    a,p = q.popleft()
    if p != 0:
        ans[a-1] += ans[p-1]
    searched[a-1] = 1
    for child in connected[a-1]:
        if searched[child-1] == 0:
            q.append((child,a))
print(*ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N,Q = (int(x) for x in input().split())
connected = [[] for _ in range(N)]
for _ in range(N-1):
    a,b = (int(x) for x in input().split())
    connected[a-1].append(b)
    connected[b-1].append(a)
counter = [0] * N
for _ in range(Q):
    p,x = (int(y) for y in input().split())
    counter[p-1] += x
ans = counter
q = deque([(1,0)])
searched = [0] * N
while q:
    a,p = q.popleft()
    if searched[a-1] == 0:
        if p != 0:
            ans[a-1] += ans[p-1]
        searched[a-1] = 1
        for child in connected[a-1]:
            q.append((child,a))
print(*ans)

Fixed submission:
from collections import deque
N,Q = (int(x) for x in input().split())
connected = [[] for _ in range(N)]
for _ in range(N-1):
    a,b = (int(x) for x in input().split())
    connected[a-1].append(b)
    connected[b-1].append(a)
counter = [0] * N
for _ in range(Q):
    p,x = (int(y) for y in input().split())
    counter[p-1] += x
ans = counter
q = deque([(1,0)])
searched = [0] * N
while q:
    a,p = q.popleft()
    if p != 0:
        ans[a-1] += ans[p-1]
    searched[a-1] = 1
    for child in connected[a-1]:
        if searched[child-1] == 0:
            q.append((child,a))
print(*ans)

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000)
from collections import deque
N,Q = (int(x) for x in input().split())
ab = [list(map(int, input().split())) for _ in range(N-1)]
px = [list(map(int, input().split())) for _ in range(Q)]
par = [0] * N
ans = [0] * N
par[0] = 500000
for i in ab:
    temp = [par[j-1] for j in i]
    wch = temp.index(0)
    par[i[wch]-1] = i[abs(wch-1)]
def count(vert):
    if vert == 1:
        prev = 0
    else:
        prev = ans[par[vert-1]-1]
    ans[vert-1] = prev + sum([px[i][1] for i in range(Q) if px[i][0] == vert])
q = deque([1])
while len(q) > 0:
    temp = q.popleft()
    if temp is not None:
        count(temp)
        children = [x for x, y in enumerate(par) if y == temp]
        for child in children:
            q.append(child+1)
print(*ans)

Fixed submission:
from collections import deque
N,Q = (int(x) for x in input().split())
connected = [[] for _ in range(N)]
for _ in range(N-1):
    a,b = (int(x) for x in input().split())
    connected[a-1].append(b)
    connected[b-1].append(a)
counter = [0] * N
for _ in range(Q):
    p,x = (int(y) for y in input().split())
    counter[p-1] += x
ans = counter
q = deque([(1,0)])
searched = [0] * N
while q:
    a,p = q.popleft()
    if p != 0:
        ans[a-1] += ans[p-1]
    searched[a-1] = 1
    for child in connected[a-1]:
        if searched[child-1] == 0:
            q.append((child,a))
print(*ans)

Buggy python submission (verdict: Runtime Error):
from collections import deque
N,Q = (int(x) for x in input().split())
ab = [list(map(int, input().split())) for _ in range(N-1)]
px = [list(map(int, input().split())) for _ in range(Q)]
par = [0] * N
ans = [0] * N
par[0] = 500000
for i in ab:
    temp = [par[j-1] for j in i]
    wch = temp.index(0)
    par[i[wch]-1] = i[abs(wch-1)]
def count(vert):
    if vert == 1:
        prev = 0
    else:
        prev = ans[par[vert-1]-1]
    ans[vert-1] = prev + sum([px[i][1] for i in range(Q) if px[i][0] == vert])
q = deque([1])
while len(q) > 0:
    temp = q.popleft()
    if temp is not None:
        count(temp)
        children = [x for x, y in enumerate(par) if y == temp]
        for child in children:
            q.append(child+1)
print(*ans)

Fixed submission:
from collections import deque
N,Q = (int(x) for x in input().split())
connected = [[] for _ in range(N)]
for _ in range(N-1):
    a,b = (int(x) for x in input().split())
    connected[a-1].append(b)
    connected[b-1].append(a)
counter = [0] * N
for _ in range(Q):
    p,x = (int(y) for y in input().split())
    counter[p-1] += x
ans = counter
q = deque([(1,0)])
searched = [0] * N
while q:
    a,p = q.popleft()
    if p != 0:
        ans[a-1] += ans[p-1]
    searched[a-1] = 1
    for child in connected[a-1]:
        if searched[child-1] == 0:
            q.append((child,a))
print(*ans)