Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
rl = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    rl[a].append(b)
    rl[b].append(a)
cnt = [0] * N
for _ in range(Q):
    p, x = map(int, input().split())
    p -= 1
    cnt[p] += x

def dfs(v, pv):
    for next_v in rl[v]:
        if next_v == pv:
            continue
        cnt[next_v] += cnt[v]
        dfs(next_v, v)
dfs(0, -1)
print(cnt)

Fixed submission:
import sys
input = sys.stdin.readline
N, Q = map(int, input().split())
to = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)

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

stack = [0]
visited = [0] * N
while stack:
    v = stack.pop()
    visited[v] = 1
    for next_v in to[v]:
        if visited[next_v] == 1:
            continue
        count[next_v] += count[v]
        stack.append(next_v)
print(*count)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
N, Q = map(int, input().rstrip().split())
to = [[] for _ in range(N)]
ans = [0] * N
def dfs(v, p=-1):
    for u in to[v]:
        if u == p:
            continue
        ans[u] += ans[v]
        dfs(u, v)
for _ in range(N-1):
    a, b = map(int, input().rstrip().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)
for _ in range(Q):
    p, x = map(int, input().rstrip().split())
    p -= 1
    ans[p] += x
dfs(0)
print(*ans)

Fixed submission:
import sys
input = sys.stdin.readline
N, Q = map(int, input().split())
to = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)

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

stack = [0]
visited = [0] * N
while stack:
    v = stack.pop()
    visited[v] = 1
    for next_v in to[v]:
        if visited[next_v] == 1:
            continue
        count[next_v] += count[v]
        stack.append(next_v)
print(*count)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**7)
N, Q = map(int, input().split())
to = [[] for _ in range(N)]
ans = [0] * N
def dfs(v, p=-1):
    for u in to[v]:
        if u == p:
            continue
        ans[u] += ans[v]
        dfs(u, v)
for _ in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)
for _ in range(Q):
    p, x = map(int, input().split())
    p -= 1
    ans[p] += x
dfs(0)
print(*ans)

Fixed submission:
import sys
input = sys.stdin.readline
N, Q = map(int, input().split())
to = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)

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

stack = [0]
visited = [0] * N
while stack:
    v = stack.pop()
    visited[v] = 1
    for next_v in to[v]:
        if visited[next_v] == 1:
            continue
        count[next_v] += count[v]
        stack.append(next_v)
print(*count)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**7)
N, Q = map(int, input().split())
to = [[] for _ in range(N)]
ans = [0] * N
def dfs(v, p=-1):
    for u in to[v]:
        if u == p:
            continue
        ans[u] += ans[v]
        dfs(u, v)
for _ in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)
for _ in range(Q):
    p, x = map(int, input().split())
    p -= 1
    ans[p] += x
dfs(0)
print(*ans)

Fixed submission:
import sys
input = sys.stdin.readline
N, Q = map(int, input().split())
to = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)

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

stack = [0]
visited = [0] * N
while stack:
    v = stack.pop()
    visited[v] = 1
    for next_v in to[v]:
        if visited[next_v] == 1:
            continue
        count[next_v] += count[v]
        stack.append(next_v)
print(*count)

Buggy python submission (verdict: Runtime Error):
def dfs(v, p=-1):
    for u in to[v]:
        if u == p:
            continue
        ans[u] += ans[v]
        dfs(u, v)

N, Q = map(int, input().split())
to = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)
ans = [0] * N
for _ in range(Q):
    p, x = map(int, input().split())
    p -= 1
    ans[p] += x
dfs(0)
print(*ans)

Fixed submission:
import sys
input = sys.stdin.readline
N, Q = map(int, input().split())
to = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)

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

stack = [0]
visited = [0] * N
while stack:
    v = stack.pop()
    visited[v] = 1
    for next_v in to[v]:
        if visited[next_v] == 1:
            continue
        count[next_v] += count[v]
        stack.append(next_v)
print(*count)