Problem p02936 (python)

Fixed submission:
import sys
sys.setrecursionlimit(2*10**9)
N, Q = map(int, input().split())
A = [[] for _ in range(N)]
for _ in range(N-1):
    i, k = map(int, input().split())
    A[i-1].append(k-1)
    A[k-1].append(i-1)
n_P = [0] * N
for _ in range(Q):
    k, n = map(int, input().split())
    n_P[k-1] += n
ans = [0] * N
visited = [0] * N
def make(num, p):
    ans[num] += n_P[num] 
    ans[num] += p
    visited[num] = 1
    for i in A[num]:
        if visited[i] == 0:
            make(i,ans[num])
    return
make(0, ans[0])
print(*ans)

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
A = [[] for _ in range(N)]
for _ in range(N-1):
    i, k = map(int, input().split())
    A[i-1].append(k-1)
    A[k-1].append(i-1)
n_P = [0] * N
for _ in range(Q):
    k, n = map(int, input().split())
    n_P[k-1] += n
ans = [0] * N
visited = [0] * N
def make(num, p):
    ans[num] += n_P[num] 
    ans[num] += p
    visited[num] = 1
    for i in A[num]:
        if visited[i] == 0:
            make(i,ans[num])
    return
make(0, ans[0])
print(*ans)

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
A = [[] for _ in range(N)]
for _ in range(N-1):
    i, k = map(int, input().split())
    A[i-1].append(k-1)
    A[k-1].append(i-1)
n_P = [0] * N
for _ in range(Q):
    k, n = map(int, input().split())
    n_P[k-1] += n
ans = [0] * N
visited = [0] * N
def make(num, p):
    ans[num] += n_P[num] 
    ans[num] += p
    visited[num] = 1
    for i in A[num]:
        if visited[i] == 0:
            make(i,ans[num])
    return
make(0, ans)
print(*ans)

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
A = [[] for _ in range(N)]
for _ in range(N-1):
    i, k = map(int, input().split())
    A[i-1].append(k-1)
    A[k-1].append(i-1)
n_P = [0] * N
for _ in range(Q):
    k, n = map(int, input().split())
    n_P[k-1] += n
ans = [0] * N
visited = [0] * N
def make(num, p):
    ans[num] += n_P[num] 
    ans[num] += p
    visited[num] = 1
    for i in A[num]:
        if visited[i] == 0:
            make(i,ans[num])
    return
for i in range(N):
    if visited[i] == 0:
        make(i, ans[i])
print(*ans)

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
A = [[] for _ in range(N)]
for _ in range(N-1):
    i, k = map(int, input().split())
    A[i-1].append(k-1)
n_P = [0] * N
for _ in range(Q):
    k, n = map(int, input().split())
    n_P[k-1] += n
ans = [0] * N
visited = [0] * N
def make(num, A, p):
    for i in A[num]:
        visited[i] = 1
        n_P[i] += p
        make(i, A, n_P[i])
    return
for i in range(N):
    if visited[i] == 0:
        make(i, A, n_P[i])
print(*n_P)

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
A = [[] for _ in range(N)]
for _ in range(N-1):
    i, k = map(int, input().split())
    A[i-1].append(k-1)
n_P = [0] * N
for _ in range(Q):
    k, n = map(int, input().split())
    n_P[k-1] += n
ans = [0] * N
visited = []
def make(num, A, p):
    for i in A[num]:
        visited.append(i)
        n_P[i] += p
        make(i, A, n_P[i])
    return
for i in range(N):
    if i not in visited:
        make(i, A, n_P[i])
print(*n_P)

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
A = [[] for _ in range(N)]
for _ in range(N-1):
    i, k = map(int, input().split())
    A[i-1].append(k-1)
n_P = [0] * N
for _ in range(Q):
    k, n = map(int, input().split())
    n_P[k-1] += n
ans = [0] * N
visited = []
def make(num, A, p):
    for i in A[num]:
        visited.append(i)
        n_P[i] += p
        make(i, A, n_P[i])
    return
for i in range(N):
    if i not in visited:
        make(0, A, n_P[0])
print(*n_P)

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
A = [[] for _ in range(N)]
for _ in range(N-1):
    i, k = map(int, input().split())
    A[i-1].append(k-1)
P = [0] * N
for _ in range(Q):
    k, n = map(int, input().split())
    P[k-1] += n
ans = [0] * N
n_P = [100, 10, 1,0]
visited = []
def make(num, A, p):
    for i in A[num]:
        visited.append(i)
        n_P[i] += p
        make(i, A, n_P[i])
    return
for i in range(N):
    if i not in visited:
        make(0, A, n_P[0])
print(*n_P)

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
A = [[] for _ in range(N)]
for _ in range(N-1):
    i, k = map(int, input().split())
    A[i-1].append(k-1)
P = [0] * N
for _ in range(Q):
    k, n = map(int, input().split())
    P[k-1] += n
ans = [0] * N
def make(num, A, p):
    ans[num] += p
    for i in A[num]:
        make(i, A, p)
    return
for i in range(0, N):
    if P[i] == 0:
        continue
    else:
        make(i, A, P[i])
print(*ans)