Buggy python submission (verdict: Runtime Error):
def BellmanFord(sv, ev, cv, num_v, source):
  #グラフの初期化
  inf=float("inf")
  dist=[inf for i in range(num_v)]
  dist[source-1]=0
  
  #辺の緩和
  for i in range(num_v):
    for s,e,c in zip(sv, ev, cv):
      if dist[0] != inf and dist[e-1] > dist[s-1] + c:
        dist[e-1] = dist[s-1] + c
        if i == n-1 and e == n-1:
          return "inf"
  
  return dist[-1]*-1

N, M = map(int, input().split())
a, b, c = [], [], []
for i in range(M):
  aa, bb, cc = map(int, input().split())
  a.append(aa)
  b.append(bb)
  c.append(cc*-1)

print(BellmanFord(a, b, c, N, 1))


Fixed submission:
import sys

INF = float('inf')

def Bellmanford(n, edges, r): #r: 始点
    d = [INF] * n
    d[r] = 0
    
    for i in range(n):
        for (u, v, c) in edges:
            if d[u] != INF and d[u] + c < d[v]:
                d[v] = d[u] + c
                if i == n-1 and v == n-1:
                    return 'inf'
    
    return -d[n-1]
    

N, M = map(int, sys.stdin.readline().split())
Edges = [None] * M

for i in range(M):
    ai, bi, ci = map(int, sys.stdin.readline().split())
    Edges[i] = (ai-1, bi-1, -ci)
    
ans = Bellmanford(N, Edges, 0)

print(ans)

Buggy python submission (verdict: Runtime Error):
def BellmanFord(sv, ev, cv, num_v, source):
  #グラフの初期化
  inf=float("inf")
  dist=[inf for i in range(num_v)]
  dist[source-1]=0
  
  #辺の緩和
  for i in range(num_v):
    for s,e,c in zip(sv, ev, cv):
      if dist[0] != inf and dist[e-1] > dist[s-1] + c:
        dist[e-1] = dist[s-1] + c
        if i==num_v-1: return "inf"
  
  return dist[num_v-1]*-1

N, M = map(int, input().split())
a, b, c = [], [], []
for i in range(M):
  aa, bb, cc = map(int, input().split())
  a.append(aa)
  b.append(bb)
  c.append(cc*-1)

print(BellmanFord(a, b, c, N, 1)[N-1]*-1)

Fixed submission:
import sys

INF = float('inf')

def Bellmanford(n, edges, r): #r: 始点
    d = [INF] * n
    d[r] = 0
    
    for i in range(n):
        for (u, v, c) in edges:
            if d[u] != INF and d[u] + c < d[v]:
                d[v] = d[u] + c
                if i == n-1 and v == n-1:
                    return 'inf'
    
    return -d[n-1]
    

N, M = map(int, sys.stdin.readline().split())
Edges = [None] * M

for i in range(M):
    ai, bi, ci = map(int, sys.stdin.readline().split())
    Edges[i] = (ai-1, bi-1, -ci)
    
ans = Bellmanford(N, Edges, 0)

print(ans)

Buggy python submission (verdict: Runtime Error):
def BellmanFord(sv, ev, cv, num_v, source):
  #グラフの初期化
  inf=float("inf")
  dist=[inf for i in range(num_v)]
  dist[source-1]=0
  
  #辺の緩和
  for i in range(num_v):
    for s,e,c in zip(sv, ev, cv):
      if dist[0] != inf and dist[e-1] > dist[s-1] + c:
        dist[e-1] = dist[s-1] + c
        if i==num_v-1: return 1
  
  return dist

N, M = map(int, input().split())
a, b, c = [], [], []
for i in range(M):
  aa, bb, cc = map(int, input().split())
  a.append(aa)
  b.append(bb)
  c.append(cc*-1)

print(BellmanFord(a, b, c, N, 1)[N-1]*-1)


Fixed submission:
import sys

INF = float('inf')

def Bellmanford(n, edges, r): #r: 始点
    d = [INF] * n
    d[r] = 0
    
    for i in range(n):
        for (u, v, c) in edges:
            if d[u] != INF and d[u] + c < d[v]:
                d[v] = d[u] + c
                if i == n-1 and v == n-1:
                    return 'inf'
    
    return -d[n-1]
    

N, M = map(int, sys.stdin.readline().split())
Edges = [None] * M

for i in range(M):
    ai, bi, ci = map(int, sys.stdin.readline().split())
    Edges[i] = (ai-1, bi-1, -ci)
    
ans = Bellmanford(N, Edges, 0)

print(ans)

Buggy python submission (verdict: Runtime Error):
def BellmanFord(sv, ev, cv, num_v, source):
  #グラフの初期化
  inf=float("inf")
  dist=[inf for i in range(num_v)]
  dist[source-1]=0
  
  #辺の緩和
  for i in range(num_v):
    for s,e,c in zip(sv, ev, cv):
      if dist[0] != inf and dist[e-1] > dist[s-1] + c:
        dist[e-1] = dist[s-1] + c
        if i==num_v-1: return -1
  
  return dist

N, M = map(int, input().split())
a, b, c = [], [], []
for i in range(M):
  aa, bb, cc = map(int, input().split())
  a.append(aa)
  b.append(bb)
  c.append(cc*-1)

print(BellmanFord(a, b, c, N, 1)[N-1]*-1)

Fixed submission:
import sys

INF = float('inf')

def Bellmanford(n, edges, r): #r: 始点
    d = [INF] * n
    d[r] = 0
    
    for i in range(n):
        for (u, v, c) in edges:
            if d[u] != INF and d[u] + c < d[v]:
                d[v] = d[u] + c
                if i == n-1 and v == n-1:
                    return 'inf'
    
    return -d[n-1]
    

N, M = map(int, sys.stdin.readline().split())
Edges = [None] * M

for i in range(M):
    ai, bi, ci = map(int, sys.stdin.readline().split())
    Edges[i] = (ai-1, bi-1, -ci)
    
ans = Bellmanford(N, Edges, 0)

print(ans)