Buggy python submission (verdict: Time Limit Exceeded):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, Q = mapint()
tree = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = mapint()
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)
late = [0]*N

for _ in range(Q):
    v, p = mapint()
    late[v-1] += p

ans = [0]*N
checked = [0]*N

def dfs(v, plus):
    plus += late[v]
    checked[v] = 1
    ans[v] = plus
    for nx in tree[v]:
        if not checked[nx]:
            dfs(nx, plus)

dfs(0, 0)
print(*ans)

Fixed submission:
N, Q = map(int, input().split())

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

from collections import deque

count = [0]*N

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

queue = deque([0])
checked  = [0]*N
while queue:
    v = queue.pop()
    checked[v] = 1
    x = count[v]
    Vs = query[v]
    for i in Vs:
        if checked[i]:
            continue
        count[i] += x
        queue.append(i)
    
print(*count)

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
query = [[] for _ in range(N)]
for i in range(N-1):
    a, b = map(int, input().split())
    query[a-1].append(b-1)

count = [0]*N
bubun = [[i] for i in range(N)]

def dfs(v):
    Vs = query[v]
    if len(Vs)==0:
        return [v]
    lis = []
    for i in Vs:
        lis += dfs(i)
    bubun[v] += lis
    return bubun[v]

dfs(0)

for i in range(Q):
    p, x = map(int, input().split())
    B = set(bubun[p-1])
    for i in B:
        count[i] += x
    
print(*count)

Fixed submission:
N, Q = map(int, input().split())

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

from collections import deque

count = [0]*N

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

queue = deque([0])
checked  = [0]*N
while queue:
    v = queue.pop()
    checked[v] = 1
    x = count[v]
    Vs = query[v]
    for i in Vs:
        if checked[i]:
            continue
        count[i] += x
        queue.append(i)
    
print(*count)

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
query = [[] for _ in range(N)]
for i in range(N-1):
    a, b = map(int, input().split())
    query[a-1].append(b-1)

count = [0]*N
bubun = [[i] for i in range(N)]

def dfs(v):
    Vs = query[v]
    if len(Vs)==0:
        return [v]
    lis = []
    for i in Vs:
        lis += dfs(i)
    bubun[v] += lis
    return bubun[v]

dfs(0)

for i in range(Q):
    p, x = map(int, input().split())
    B = bubun[p-1]
    for i in B:
        count[i] += x
    
print(*count)

Fixed submission:
N, Q = map(int, input().split())

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

from collections import deque

count = [0]*N

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

queue = deque([0])
checked  = [0]*N
while queue:
    v = queue.pop()
    checked[v] = 1
    x = count[v]
    Vs = query[v]
    for i in Vs:
        if checked[i]:
            continue
        count[i] += x
        queue.append(i)
    
print(*count)

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
query = [[] for _ in range(N)]
for i in range(N-1):
    a, b = map(int, input().split())
    query[a-1].append(b-1)

count = [0]*N

def dfs(v):
    global x
    if checked[v]:
        return
    checked[v] = 1
    count[v] += x
    for i in query[v]:
        if not checked[i]:
            dfs(i)

for i in range(Q):
    p, x = map(int, input().split())
    checked = [0]*N
    dfs(p-1)

print(*count)

Fixed submission:
N, Q = map(int, input().split())

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

from collections import deque

count = [0]*N

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

queue = deque([0])
checked  = [0]*N
while queue:
    v = queue.pop()
    checked[v] = 1
    x = count[v]
    Vs = query[v]
    for i in Vs:
        if checked[i]:
            continue
        count[i] += x
        queue.append(i)
    
print(*count)