Problem p02936 (python)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N,Q = map(int,input().split())
aLst = [[int(x) for x in input().split()] for _ in range(N-1)]
pLst = [[int(x) for x in input().split()] for _ in range(Q)]

tmpLst = [[] for _ in range(N+1)]
for i, j in aLst:
    tmpLst[i].append(j)
    tmpLst[j].append(i)

ansLst = [0] * (N + 1)
for i,j in pLst:
    ansLst[i] += j

def dfs(v, p):
    for i in tmpLst[v]:
        if i == p:
            continue
        ansLst[i] += ansLst[v]
        dfs(i, v)


dfs(1, 0)

ans = ' '.join(map(str, ansLst[1:]))
print(ans)

Buggy submission (verdict: Runtime Error):


N,Q = map(int,input().split())
aLst = [[int(i) for i in input().split()] for _ in range(N-1)]
pLst = [[int(i) for i in input().split()] for _ in range(Q)]
to = [[]for _ in range(N+1)]

for a,b in aLst:
    to[a].append(b)
    to[b].append(a)

ps = [0]*(N+1)
for a,b in pLst:
    ps[a] += b

def dfs(v, i):
    for j in to[v]:
        if j == i:
            continue
        ps[j] += ps[v]
        dfs(j,v)

dfs(1,0)
print(' '.join(map(str, ps[1:])))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N,Q = map(int,input().split())
aLst = [[int(i) for i in input().split()] for _ in range(N-1)]
pLst = [[int(i) for i in input().split()] for _ in range(Q)]
to = [[]for _ in range(N+1)]

for a,b in aLst:
    to[a].append(b)
    to[b].append(a)

ps = [0]*(N+1)
for a,b in pLst:
    ps[a] += b

def dfs(v, i):
    for j in to[v]:
        if j == i:
            continue
        ps[j] += ps[v]
        dfs(j,v)

dfs(1,0)
print(' '.join(map(str, ps[1:])))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N,Q = map(int,input().split())
aLst = [[int(i) for i in input().split()] for _ in range(N-1)]
pLst = [[int(i) for i in input().split()] for _ in range(Q)]
to = [[]for _ in range(N+1)]

for a,b in aLst:
    to[a].append(b)
    to[b].append(a)

ps = [0]*(N+1)
for a,b in pLst:
    ps[a] += b

def dfs(v, i):
    for j in to[v]:
        if i == j:
            continue
        ps[j] += ps[v]
        dfs(j,v)

dfs(1,0)
print(' '.join(map(str, ps[1:])))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N,Q = map(int,input().split())
aLst = [[int(i) for i in input().split()] for _ in range(N-1)]
pLst = [[int(i) for i in input().split()] for _ in range(Q)]
to = [[]for _ in range(N)]

for a,b in aLst:
    to[a-1].append(b-1)
    to[b-1].append(a-1)

ps = [0]*N
for a,b in pLst:
    ps[a-1] += b

def dfs(v, i):
    for j in to[v]:
        if i == j:
            continue
        ps[j] += ps[v]
        dfs(j,v)

dfs(0,-1)
print(' '.join(map(str, ps)))

Buggy submission (verdict: Runtime Error):
N,Q = map(int,input().split())
aLst = [[int(i) for i in input().split()] for _ in range(N-1)]
pLst = [[int(i) for i in input().split()] for _ in range(Q)]
to = [[]for _ in range(N)]

for i in aLst:
    a = i[0] -1
    b = i[1] -1
    to[a].append(b)
    to[b].append(a)

ps = [0]*N
for i in pLst:
    a = i[0] -1
    b = i[1]
    ps[a] += b

def dfs(v, i):
    for j in to[v]:
        if i == j:
            continue
        ps[j] += ps[v]
        dfs(j,v)

dfs(0,-1)
print(' '.join(map(str, ps)))

Buggy submission (verdict: Runtime Error):
N,Q = map(int,input().split())
aLst = [[int(i) for i in input().split()] for _ in range(N-1)]
pLst = [[int(i) for i in input().split()] for _ in range(Q)]
to = [[]for _ in range(N)]

for i in aLst:
    a = i[0] -1
    b = i[1] -1
    to[a].append(b)
    to[b].append(a)

ps = [0]*N
for i in pLst:
    a = i[0] -1
    b = i[1]
    ps[a] += b

def dfs(v, i):
    for j in to[v]:
        if i == j:
            continue
        ps[j] += ps[v]
        dfs(j,v)

dfs(0,-1)
print(' '.join(map(str, ps)))