Problem p03722 (python)

Fixed submission:
# coding: utf-8
n,m=map(int,input().split())
edge=[]
for i in range(m):
    a,b,c=map(int,input().split())
    edge.append((a-1,b-1,-c))
inf=99999999999999999999
d=[inf for i in range(n)]
d[0]=0
count=0
while count<n+1:
    count+=1
    if count==n:
        tmp=d[n-1]
    update=False
    for i in range(m):
        f,t,cost=edge[i]
        if(d[t]>d[f]+cost):
            d[t]=d[f]+cost
            update=True
    if count==n and tmp!=d[n-1]:
        print('inf')
        break
    if not update:
        print(-d[n-1])
        break
else:
    print(-d[n-1])

Buggy submission (verdict: Runtime Error):
# coding: utf-8
n,m=map(int,input().split())
score={}
muki={}
kita={}

for i in range(1,n+1):
    score[i]=0
    muki[i]=[(-1,0)]
    kita[i]=0

for i in range(m):
    a,b,c=map(int,input().split())
    if muki[a][0][0]==-1:
        muki[a]=[(b,c)]
    else:
        muki[a].append((b,c))
 
def heiro(g,moto):
    for n in muki[g]:
        if n[0]==moto:
            print('inf')
            exit()
        elif n[0]!=-1:
            heiro(n[0],moto)

for i in range(1,n+1):
    heiro(i,i)

def check(moto):
    for p in muki[moto]:
        if kita[p[0]]==0 or score[p[0]]<score[moto]+p[1]:
            score[p[0]]=score[moto]+p[1]
            kita[p[0]]+=1
        if muki[p[0]][0][0]!=-1:
            check(p[0])
            
check(1)
print(score[n])

Buggy submission (verdict: Runtime Error):
# coding: utf-8
n,m=map(int,input().split())
score={}
muki={}
kita={}

for i in range(1,n+1):
    score[i]=0
    muki[i]=[(-1,0)]
    kita[i]=0

for i in range(m):
    a,b,c=map(int,input().split())
    if muki[a][0][0]==-1:
        muki[a]=[(b,c)]
    else:
        muki[a].append((b,c))
        
def heiro(g,moto):
    for n in muki[g]:
        if n[0]==moto:
            print('inf')
            exit()
        elif n[0]!=-1:
            heiro(n[0],moto)

for i in range(1,n+1):
    heiro(i,i)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
n,m=map(int,input().split())
data=[]
dic={}
muki={}
kita={}
for i in range(1,n+1):
    dic[i]=0
    muki[i]=[(-1,0)]
    kita[i]=0

def heiroCheck(moto,m):
    for i in muki[moto]:
        if i[0]!=m:
            if i[0]!=-1:
                heiroCheck(i[0],m)
        else:
            print('inf')
            exit()

for i in range(m):
    a,b,c=map(int,input().split())
    if muki[a][0]!=(-1,0):
        muki[a].append((b,c))
    else:
        muki[a]=[(b,c)]

for i in range(1,n+1):
    heiroCheck(i,i)

def check(moto):
    for p in muki[moto]:
        if kita[p[0]]==0 or dic[p[0]]<dic[moto]+p[1]:
            dic[p[0]]=dic[moto]+p[1]
            kita[p[0]]+=1
        if muki[p[0]][0][0]!=-1:
            check(p[0])
            
check(1)
print(dic[n])

Buggy submission (verdict: Runtime Error):
# coding: utf-8
n,m=map(int,input().split())
data=[]
dic={}
muki={}
kita={}
for i in range(1,n+1):
    dic[i]=0
    muki[i]=[(-1,0)]
    kita[i]=0

for i in range(m):
    a,b,c=map(int,input().split())
    if muki[a][0]!=(-1,0):
        muki[a].append((b,c))
    else:
        muki[a]=[(b,c)]
def check(moto):
    for p in muki[moto]:
        if kita[p[0]]==0 or dic[p[0]]<dic[moto]+p[1]:
            dic[p[0]]=dic[moto]+p[1]
            kita[p[0]]+=1
    tmp=muki[moto]
    muki[moto]=[(-2,0)]
    for p in tmp:
        if muki[p[0]][0][0]==-2:
            print('inf')
            exit()
        elif muki[p[0]][0][0]!=-1:
            check(p[0])
check(1)
print(dic[n])

Buggy submission (verdict: Runtime Error):
# coding: utf-8
n,m=map(int,input().split())
data=[]
dic={}
muki={}
kaburi=[]
kita={}
for i in range(1,n+1):
    dic[i]=0
    muki[i]=[(-1,0)]
    kita[i]=0
for i in range(m):
    a,b,c=map(int,input().split())
    if (b,a) not in kaburi:
        kaburi.append((a,b))
    else:
        print('inf')
        exit()
    if muki[a][0]!=(-1,0):
        muki[a].append((b,c))
    else:
        muki[a]=[(b,c)]
def check(moto):
    for p in muki[moto]:
        if kita[p[0]]==0 or dic[p[0]]<dic[moto]+p[1]:
            dic[p[0]]=dic[moto]+p[1]
            kita[p[0]]+=1
        if p[0]!=n:
            check(p[0])
            

check(1)
print(dic[n])