Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
abc=[list(map(int,input().split())) for _ in [0]*m]
g=[[] for _ in [0]*n]
[g[a-1].append([b-1,c]) for a,b,c in abc]

loop=set()
d=[-10**15 for _ in [0]*n]
d[0]=0
q=[[0,1]]
s=set()
l=[]
while q:
    item,depth=q.pop()
    if depth<=len(s):
        for _ in range(len(s)-depth+1):
            rmv=l.pop()
            s.remove(rmv)
    l.append(item)
    s.add(item)
    for i,dist in g[item]:
        if d[i]<d[item]+dist:
            if i in s:
                loop.add(i)
                continue
            d[i]=d[item]+dist
            q.append([i,depth+1])
  
c=[False for _ in [0]*n]
for x in loop:
    if c[x]==True:
        continue
    q=[x]
    c[x]=True
    while q:
        item=q.pop()
        for i,j in g[item]:
            if c[i]==False:
                c[i]=True
                q.append(i)
if c[n-1]==True:
    print("inf")
else:
    print(d[n-1])

Fixed submission:
n,m=map(int,input().split())
abc=[list(map(int,input().split())) for _ in [0]*m]
g=[[] for _ in [0]*n]
[g[a-1].append([b-1,c]) for a,b,c in abc]

dist=[-10**15 for _ in [0]*n]
dist[0]=0
a,b=-10**15,-10**15

for _ in range(n):
    for p in range(n):
        for i,j in g[p]:
            dist[i]=max(dist[i],dist[p]+j)
    a,b=b,dist[n-1]

if a==b:
    print(a)
else:
    print("inf")

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
abc=[list(map(int,input().split())) for _ in [0]*m]
g=[[] for _ in [0]*n]
[g[a-1].append([b-1,c]) for a,b,c in abc]

loop=set()
d=[-10**15 for _ in [0]*n]
d[0]=0
q=[[0,1]]
s=set()
l=[]
while q:
    item,depth=q.pop()
    if depth<=len(s):
        for _ in range(len(s)-depth+1):
            rmv=l.pop()
            s.remove(rmv)
    l.append(item)
    s.add(item)
    for i,dist in g[item]:
        if d[i]<d[item]+dist:
            if i in s:
                loop.add(i)
                continue
            d[i]=d[item]+dist
            q.append([i,depth+1])
    
for x in loop:
    q=[x]
    c=[False for _ in [0]*n]
    c[x]=True
    while q:
        item=q.pop()
        for i,j in g[item]:
            if c[i]==False:
                c[i]=True
                q.append(i)
    if c[n-1]==True:
        print("inf")
        break
else:
    print(d[n-1])

Fixed submission:
n,m=map(int,input().split())
abc=[list(map(int,input().split())) for _ in [0]*m]
g=[[] for _ in [0]*n]
[g[a-1].append([b-1,c]) for a,b,c in abc]

dist=[-10**15 for _ in [0]*n]
dist[0]=0
a,b=-10**15,-10**15

for _ in range(n):
    for p in range(n):
        for i,j in g[p]:
            dist[i]=max(dist[i],dist[p]+j)
    a,b=b,dist[n-1]

if a==b:
    print(a)
else:
    print("inf")

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
abc=[list(map(int,input().split())) for _ in [0]*m]
g=[[] for _ in [0]*n]
[g[a-1].append([b-1,c]) for a,b,c in abc]

loop=set()
d=[-10**15 for _ in [0]*n]
d[0]=0
q=[[0,1]]
s=set()
l=[]
while q:
    item,depth=q.pop()
    if depth<=len(s):
        for _ in range(len(s)-depth+1):
            rmv=l.pop()
            s.remove(rmv)
    l.append(item)
    s.add(item)
    for i,dist in g[item]:
        if d[i]<d[item]+dist:
            if i in s:
                loop.add(i)
                continue
            d[i]=d[item]+dist
            q.append([i,depth+1])
    
def check(x):
    q=[x]
    c=[False for _ in [0]*n]
    c[x]=True
    while q:
        item=q.pop()
        for i,j in g[item]:
            if c[i]==False:
                c[i]=True
                q.append(i)
        if c[n-1]==True:
            return True
    else:
        return False
    
for x in loop:
    q=[x]
    c=[False for _ in [0]*n]
    c[x]=True
    while q:
        item=q.pop()
        for i,j in g[item]:
            if c[i]==False:
                c[i]=True
                q.append(i)
    if c[n-1]==True:
        print("inf")
        break
else:
    print(d[n-1])

Fixed submission:
n,m=map(int,input().split())
abc=[list(map(int,input().split())) for _ in [0]*m]
g=[[] for _ in [0]*n]
[g[a-1].append([b-1,c]) for a,b,c in abc]

dist=[-10**15 for _ in [0]*n]
dist[0]=0
a,b=-10**15,-10**15

for _ in range(n):
    for p in range(n):
        for i,j in g[p]:
            dist[i]=max(dist[i],dist[p]+j)
    a,b=b,dist[n-1]

if a==b:
    print(a)
else:
    print("inf")

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
abc=[list(map(int,input().split())) for _ in [0]*m]
g=[[] for _ in [0]*n]
[g[a-1].append([b-1,c]) for a,b,c in abc]

loop=set()
d=[-10**15 for _ in [0]*n]
d[0]=0
q=[[0,1]]
s=set()
l=[]
while q:
    item,depth=q.pop()
    if depth<=len(s):
        for _ in range(len(s)-depth+1):
            rmv=l.pop()
            s.remove(rmv)
    l.append(item)
    s.add(item)
    for i,dist in g[item]:
        if d[i]<d[item]+dist:
            if i in s:
                loop.add(i)
                continue
            d[i]=d[item]+dist
            q.append([i,depth+1])
    
def check(x):
    q=[x]
    c=[False for _ in [0]*n]
    c[x]=True
    while q:
        item=q.pop()
        for i,j in g[item]:
            if c[i]==False:
                c[i]=True
                q.append(i)
    return c[n-1]
  
for i in loop:
    if check(i)==True:
        print("inf")
        break
else:
    print(d[n-1])

Fixed submission:
n,m=map(int,input().split())
abc=[list(map(int,input().split())) for _ in [0]*m]
g=[[] for _ in [0]*n]
[g[a-1].append([b-1,c]) for a,b,c in abc]

dist=[-10**15 for _ in [0]*n]
dist[0]=0
a,b=-10**15,-10**15

for _ in range(n):
    for p in range(n):
        for i,j in g[p]:
            dist[i]=max(dist[i],dist[p]+j)
    a,b=b,dist[n-1]

if a==b:
    print(a)
else:
    print("inf")

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
abc=[list(map(int,input().split())) for _ in [0]*m]
g=[[] for _ in [0]*n]
[g[a-1].append([b-1,c]) for a,b,c in abc]

loop=set()
d=[-10**15 for _ in [0]*n]
d[0]=0
q=[[0,1]]
s=set()
l=[]
while q:
    item,depth=q.pop()
    if depth<=len(s):
        for _ in range(len(s)-depth+1):
            rmv=l.pop()
            s.remove(rmv)
    l.append(item)
    s.add(item)
    for i,dist in g[item]:
        if d[i]<d[item]+dist:
            if i in s:
                loop.add(i)
                continue
            d[i]=d[item]+dist
            q.append([i,depth+1])
    
def check(x):
    q=[x]
    c=[False for _ in [0]*n]
    c[x]=True
    while q:
        item=q.pop()
        for i,j in g[item]:
            if c[i]==False:
                c[i]=True
                q.append(i)
        if c[n-1]==True:
            return True
            break
    else:
        return False
    
for i in loop:
    if check(i)==True:
        print("inf")
        break
else:
    print(d[n-1])

Fixed submission:
n,m=map(int,input().split())
abc=[list(map(int,input().split())) for _ in [0]*m]
g=[[] for _ in [0]*n]
[g[a-1].append([b-1,c]) for a,b,c in abc]

dist=[-10**15 for _ in [0]*n]
dist[0]=0
a,b=-10**15,-10**15

for _ in range(n):
    for p in range(n):
        for i,j in g[p]:
            dist[i]=max(dist[i],dist[p]+j)
    a,b=b,dist[n-1]

if a==b:
    print(a)
else:
    print("inf")

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
abc=[list(map(int,input().split())) for _ in [0]*m]
g=[[] for _ in [0]*n]
[g[a-1].append([b-1,c]) for a,b,c in abc]

loop=set()
d=[-10**15 for _ in [0]*n]
d[0]=0
q=[[0,1]]
s=set()
l=[]
while q:
    item,depth=q.pop()
    if depth<=len(s):
        for _ in range(len(s)-depth+1):
            rmv=l.pop()
            s.remove(rmv)
    l.append(item)
    s.add(item)
    for i,dist in g[item]:
        if d[i]<d[item]+dist:
            if i in s:
                loop.add(i)
                continue
            d[i]=d[item]+dist
            q.append([i,depth+1])
    
def check(x):
    q=[x]
    c=[False for _ in [0]*n]
    c[x]=True
    while q:
        item=q.pop()
        for i,j in g[item]:
            if c[i]==False:
                c[i]=True
                q.append(i)
    return c[n-1]
  
for i in loop:
    if check(i)==True:
        print("inf")
        break
else:
    print(d[n-1])

Fixed submission:
n,m=map(int,input().split())
abc=[list(map(int,input().split())) for _ in [0]*m]
g=[[] for _ in [0]*n]
[g[a-1].append([b-1,c]) for a,b,c in abc]

dist=[-10**15 for _ in [0]*n]
dist[0]=0
a,b=-10**15,-10**15

for _ in range(n):
    for p in range(n):
        for i,j in g[p]:
            dist[i]=max(dist[i],dist[p]+j)
    a,b=b,dist[n-1]

if a==b:
    print(a)
else:
    print("inf")

Buggy python submission (verdict: Time Limit Exceeded):
from copy import deepcopy as dc
n,m=map(int,input().split())
abc=[list(map(int,input().split())) for _ in [0]*m]
g=[[] for _ in [0]*n]
[g[a-1].append([b-1,c]) for a,b,c in abc]

d=[-10**15 for _ in [0]*n]
d[0]=0
q=[[0,set()]]
flag=0
loop=set()
while q:
    item,s=q.pop()
    #print(item,s)
    s.add(item)
    #print(g[item])
    for i,dist in g[item]:
        if d[i]<d[item]+dist:
            if i in s:
                #print(i)
                loop.add(i)
                continue
            d[i]=d[item]+dist
            q.append([i,dc(s)])
    
def check(x):
    q=[x]
    c=[False for _ in [0]*n]
    c[x]=True
    while q:
        item=q.pop()
        for i,j in g[item]:
            if c[i]==False:
                c[i]=True
                q.append(i)
    return c[n-1]
for i in loop:
    if check(i)==True:
        print("inf")
        break
else:
    print(d[n-1])

Fixed submission:
n,m=map(int,input().split())
abc=[list(map(int,input().split())) for _ in [0]*m]
g=[[] for _ in [0]*n]
[g[a-1].append([b-1,c]) for a,b,c in abc]

dist=[-10**15 for _ in [0]*n]
dist[0]=0
a,b=-10**15,-10**15

for _ in range(n):
    for p in range(n):
        for i,j in g[p]:
            dist[i]=max(dist[i],dist[p]+j)
    a,b=b,dist[n-1]

if a==b:
    print(a)
else:
    print("inf")