Problem p02936 (python)

Fixed submission:
n,q = map(int,input().split())
rl = [0] * n
al = [0] * n
for i in range(n-1):
    a,b = map(int,input().split())
    rl[b-1] = a -1
for j in range(q):
    p,x = map(int,input().split())
    al[p-1] += x
for k in range(1,n):
    al[k] += al[rl[k]]
print(*al)

Buggy submission (verdict: Runtime Error):
n,q=map(int,input().split())

tree = [[] for _ in range(n)]
ope = [0]*n
opef=[False]*n
ret=[0]*n

for i in range(n-1):
    a,b=map(int,input().split())
    tree[a-1].append(b-1)

def counter(target,num):
    global ret
    global ope
    global opef
    ret[target]+=num
    if not tree[target]:
        return
    for i in tree[target]:
        tmp=0
        if opef[i]==False:
            tmp=ope[i]
            opef[i]=True
        counter(i,num+tmp)

for _ in range(q):
    p,x=map(int,input().split())
    ope[p-1]+=x

for i in range(n):
    if opef[i]==False:
        opef[i]=True
        counter(i,ope[i])

print(*ret)

Buggy submission (verdict: Runtime Error):
n,q=map(int,input().split())

tree = [[] for _ in range(n)]
ope = [0]*n
opef=[False]*n
ret=[0]*n

for i in range(n-1):
    a,b=map(int,input().split())
    tree[a-1].append(b-1)

def counter(target,num):
    global ret
    global ope
    global opef
    

    ret[target]+=num
    if not tree[target]:
        return
    for i in tree[target]:
        tmp=0
        if opef[i]==False:
            tmp=ope[i]
            opef[i]=True
        counter(i,num+tmp)

for _ in range(q):
    p,x=map(int,input().split())
    ope[p-1]+=x

for i in range(n):
    if opef[i]==False:
        opef[i]=True
        counter(i,ope[i])

print(*ret)

Buggy submission (verdict: Runtime Error):
n,q=map(int,input().split())

tree = [[] for _ in range(n)]
ope = [0]*n
ret=[0]*n

for i in range(n-1):
    a,b=map(int,input().split())
    tree[a-1].append(b-1)

def counter(target,num):
    global ret
    ret[target]+=num
    if not tree[target]:
        return
    for i in tree[target]:
        counter(i,num)

for _ in range(q):
    p,x=map(int,input().split())
    ope[p-1]+=x

for i in range(n):
    counter(i,ope[i])

print(*ret)

Buggy submission (verdict: Runtime Error):
n,q=map(int,input().split())

tree = [[] for _ in range(n)]
ret=[0]*n

for i in range(n-1):
    a,b=map(int,input().split())
    tree[a-1].append(b-1)

def counter(target,num):
    global ret
    ret[target]+=num
    if not tree[target]:
        return
    for i in tree[target]:
        counter(i,num)
for _ in range(q):
    p,x=map(int,input().split())
    counter(p-1,x)

print(*ret)

Buggy submission (verdict: Runtime Error):
n,q=map(int,input().split())

tree = [[] for _ in range(n)]
ret=[0]*n

for i in range(n-1):
    a,b=map(int,input().split())
    tree[a-1].append(b-1)

#print(tree)

def counter(target,num):
    global ret
    ret[target]+=num
    if not tree[target]:
        return
    for i in tree[target]:
        counter(i,num)
for _ in range(q):
    p,x=map(int,input().split())
    counter(p-1,x)

print(*ret)

Buggy submission (verdict: Runtime Error):
n,q=map(int,input().split())

tree = [[] for _ in range(n)]
ret=[0]*n

for i in range(n-1):
    a,b=map(int,input().split())
    tree[a-1].append(b-1)

#print(tree)

def counter(target,num):
    global ret
    ret[target]+=num
    if not tree[target]:
        return
    for i in tree[target]:
        counter(i,num)
for _ in range(q):
    p,x=map(int,input().split())
    counter(p-1,x)

print(ret)