Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int,input().split())
side = [[]for _ in range(N)]
for _ in range(M):
    a,b,c = map(int,input().split())
    side[a-1].append([b-1,c])
node = [-float('inf')]*N
node[0] = 0
queue = [0]
nque = []
for i in range(N+5):
    while queue:
        q = queue.pop(-1)
        for a,c in side[q]:
            if node[a] < node[q]+c:
                node[a] = node[q]+c
                nque.append(a)
    queue = nque[:]
    nque = []

while queue:
    q = queue.pop(-1)
    for a,c in side[q]:
        if node[a] < node[q]+c:
            node[a] = float('inf')
            queue.append(a)

print(node[-1])

Fixed submission:
N,M = map(int,input().split())
gra = [[]for i in range(N)]
p = [[0]+[-float("inf")]*(N-1) for i in range(N*2+1)]
p[0][0] = 0
for i in range(M):
    a,b,c = map(int,input().split())
    gra[a-1].append([b-1,c])
for i in range(N*2):
    for j in range(N):
        for b,c in gra[j]:
            p[i+1][b] = max(p[i+1][b],p[i][j]+c,p[i][b])
print(["inf",p[N][-1]][p[N][-1] == p[-1][-1]])

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int,input().split())
side = [[]for _ in range(N)]
for _ in range(M):
    a,b,c = map(int,input().split())
    side[a-1].append([b-1,c])
node = [-float('inf')]*N
node[0] = 0
queue = [0]
nque = []
for i in range(N+5):
    while queue:
        q = queue.pop(-1)
        for a,c in side[q]:
            if node[a] < node[q]+c:
                node[a] = node[q]+c
                nque.append(a)
    queue = nque[:]
    nque = []
ans = node[-1]
for i in range(N+5):
    while queue:
        q = queue.pop(-1)
        for a,c in side[q]:
            if node[a] < node[q]+c:
                node[a] = node[q]+c
                nque.append(a)
    queue = nque[:]
    nque = []
if node[-1] == ans:
    print(ans)
else:
    print('inf')

Fixed submission:
N,M = map(int,input().split())
gra = [[]for i in range(N)]
p = [[0]+[-float("inf")]*(N-1) for i in range(N*2+1)]
p[0][0] = 0
for i in range(M):
    a,b,c = map(int,input().split())
    gra[a-1].append([b-1,c])
for i in range(N*2):
    for j in range(N):
        for b,c in gra[j]:
            p[i+1][b] = max(p[i+1][b],p[i][j]+c,p[i][b])
print(["inf",p[N][-1]][p[N][-1] == p[-1][-1]])

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int,input().split())
side = [[]for _ in range(N)]
for _ in range(M):
    a,b,c = map(int,input().split())
    side[a-1].append([b-1,c])
node = [-float('inf')]*N
node[0] = 0
queue = [0]
nque = []
for i in range(N+5):
    while queue:
        q = queue.pop(-1)
        for a,c in side[q]:
            if node[a] < node[q]+c:
                node[a] = node[q]+c
                nque.append(a)
    queue = nque[:]
    nque = []
ans = node[-1]
for i in range(N+5):
    while queue:
        q = queue.pop(-1)
        for a,c in side[q]:
            if node[a] < node[q]+c:
                node[a] = node[q]+c
                nque.append(a)
    queue = nque[:]
    nque = []
if node[-1] == ans:
    print(ans)
else:
    print('inf')

Fixed submission:
N,M = map(int,input().split())
gra = [[]for i in range(N)]
p = [[0]+[-float("inf")]*(N-1) for i in range(N*2+1)]
p[0][0] = 0
for i in range(M):
    a,b,c = map(int,input().split())
    gra[a-1].append([b-1,c])
for i in range(N*2):
    for j in range(N):
        for b,c in gra[j]:
            p[i+1][b] = max(p[i+1][b],p[i][j]+c,p[i][b])
print(["inf",p[N][-1]][p[N][-1] == p[-1][-1]])

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
gra = [[]for i in range(N)]
p = [[0]+[-float("inf")]*(N-1) for i in range(N*2+1)]
p[0][0] = 0
for i in range(M):
    a,b,c = map(int,input().split())
    gra[a-1].append([b-1,c])
for i in range(N*2):
    for j in range(N):
        for b,c in gra[j]:
            p[i+1][b] = max(p[i+1][b],p[i][j]+c,p[i][b])
print(["inf",p[N][-1]][p[N][-1] == p[-1][-1]])

Fixed submission:
N,M = map(int,input().split())
gra = [[]for i in range(N)]
p = [[0]+[-float("inf")]*(N-1) for i in range(N*2+1)]
p[0][0] = 0
for i in range(M):
    a,b,c = map(int,input().split())
    gra[a-1].append([b-1,c])
for i in range(N*2):
    for j in range(N):
        for b,c in gra[j]:
            p[i+1][b] = max(p[i+1][b],p[i][j]+c,p[i][b])
print(["inf",p[N][-1]][p[N][-1] == p[-1][-1]])