Buggy python submission (verdict: Runtime Error):
from collections import defaultdict as dd
def main():
    N, M = map(int, input().split())

    MAP = [[0]*N for x in range(N)]
    E = []
    for m in range(M):
        a,b,c = map(int, input().split())
        MAP[a-1][b-1] = c
        E.append((a-1,b-1,c))

    dp = [-float('inf')]*N
    dp[0] = 0
    updated = set([0])
    for count in range(1, 2*N+1):  # N
        preupdated = list(updated)
        updated = set([])
        for e in preupdated:
            a,b,c = E[e]
            if max(dp[b], dp[b]) < dp[a] + c:
                updated.add(b)
                dp[b] = dp[a] + c
        if count == N-1:
            tmp = dp[N-1]

    # print(tmp, dp[N-1])
    if dp[N-1] == tmp:
        print(tmp)
    else:
        print('inf')


if __name__ == "__main__":
    # global stime
    # stime = time.clock()
    main()



Fixed submission:
import math 
from collections import defaultdict as dd
def main():
    N, M = map(int, input().split())

    MAP = [[]*N for x in range(N)]
    E = []
    for m in range(M):
        a,b,c = map(int, input().split())
        MAP[a-1].append((b-1, c))
        E.append((a-1,b-1,c))

    dp = [-float('inf')]*N
    dp[0] = 0
    updated = set([0])
    for count in range(1, 2*N+1):  # N
        preupdated = list(updated)
        updated = set([])
        for a in preupdated:
            for b,c in MAP[a]:
                if max(dp[b], dp[b]) < dp[a] + c:
                    updated.add(b)
                    dp[b] = dp[a] + c
        if count == N-1:
            tmp = dp[N-1]

    # print(tmp, dp[N-1])
    if dp[N-1] == tmp:
        print(tmp)
    else:
        print('inf')


if __name__ == "__main__":
    # global stime
    # stime = time.clock()
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, M = map(int, input().split())

    MAP = [[0]*N for x in range(N)]
    E = []
    for m in range(M):
        a,b,c = map(int, input().split())
        MAP[a-1][b-1] = c
        E.append((a-1,b-1,c))

    dp = [[-float('inf')]*N for x in range(2*N+1)]
    dp[0][0] = 0
    count = 1
    for i in range(2*N):  # N
        # for n in range(N):
        #     print(count,n)
        #     dp[count][n] = max(dp[count][n], dp[count-1][n])
        for e in E:
            a,b,c = e
            dp[count][b] = max(dp[count][b], dp[count-1][b], dp[count-1][a] + c)
        count += 1

    # print(dp[N-1][N-1], dp[N][N-1])
    if dp[2*N][N-1] == dp[N-1][N-1]:
        print(dp[N-1][N-1])
    else:
        print('inf')


if __name__ == "__main__":
    # global stime
    # stime = time.clock()
    main()


Fixed submission:
import math 
from collections import defaultdict as dd
def main():
    N, M = map(int, input().split())

    MAP = [[]*N for x in range(N)]
    E = []
    for m in range(M):
        a,b,c = map(int, input().split())
        MAP[a-1].append((b-1, c))
        E.append((a-1,b-1,c))

    dp = [-float('inf')]*N
    dp[0] = 0
    updated = set([0])
    for count in range(1, 2*N+1):  # N
        preupdated = list(updated)
        updated = set([])
        for a in preupdated:
            for b,c in MAP[a]:
                if max(dp[b], dp[b]) < dp[a] + c:
                    updated.add(b)
                    dp[b] = dp[a] + c
        if count == N-1:
            tmp = dp[N-1]

    # print(tmp, dp[N-1])
    if dp[N-1] == tmp:
        print(tmp)
    else:
        print('inf')


if __name__ == "__main__":
    # global stime
    # stime = time.clock()
    main()