Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
import heapq

def main():
    N,M = map(int,input().split())
    INF = 10**10+1
    root = [[INF for _ in range(N)] for _ in range(N)]
    for i in range(N-1):
        root[i+1][i] = 0
    for _ in range(M):
        a,b,c = map(int,input().split())
        root[a-1][b-1] = c
        root[b-1][a-1] = c
    
    dist = [INF for _ in range(N)]
    que = [(0,0)]
    dist[0] = 0
    while que:
        dif,now = heapq.heappop(que)
        for f,fol in enumerate(root[now]):
            if (fol != INF and dist[f] > dist[now] + fol):
                dist[f] = dist[now] + fol
                heapq.heappush(que,(dist[f],f))
                
    if dist[-1] == INF:
        print(-1)
    else:
        print(dist[-1])

if __name__ == "__main__":
    main()


Fixed submission:
import sys
input = sys.stdin.readline
import heapq

def main():
    N,M = map(int,input().split())
    INF = 10**15
    root = [[] for _ in range(N)]
    for i in range(N-1):
        root[i+1].append((0,i))
    for _ in range(M):
        l,r,c = map(int,input().split())
        root[l-1].append((c,r-1))
    
    dist = [INF for _ in range(N)]
    q = [(0,0)]
    dist[0] = 0
    while q:
        d,now = heapq.heappop(q)
        if dist[now] < d:
            continue
        for cost,fol in root[now]:
            _d = d+cost
            if dist[fol] > _d:
                dist[fol] = _d
                heapq.heappush(q,(_d,fol))

    if dist[-1] == INF:
        print(-1)
    else:
        print(dist[-1])

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
from scipy.sparse.csgraph import csgraph_from_dense,dijkstra

def main():
    N,M = map(int,input().split())
    edge = [[-1 for _ in range(N)] for _ in range(N)]
    for i in range(N-1):
        edge[i+1][i] = 0
    for _ in range(M):
        l,r,c = map(int,input().split())
        edge[l-1][r-1] = c

    G = csgraph_from_dense(edge,null_value = -1)
    if dijkstra(G,indices = 0)[-1] == float("inf"):
        print(-1)
    else:
        print(int(dijkstra(G,indices = 0)[-1]))

if __name__ == "__main__":
    main()


Fixed submission:
import sys
input = sys.stdin.readline
import heapq

def main():
    N,M = map(int,input().split())
    INF = 10**15
    root = [[] for _ in range(N)]
    for i in range(N-1):
        root[i+1].append((0,i))
    for _ in range(M):
        l,r,c = map(int,input().split())
        root[l-1].append((c,r-1))
    
    dist = [INF for _ in range(N)]
    q = [(0,0)]
    dist[0] = 0
    while q:
        d,now = heapq.heappop(q)
        if dist[now] < d:
            continue
        for cost,fol in root[now]:
            _d = d+cost
            if dist[fol] > _d:
                dist[fol] = _d
                heapq.heappush(q,(_d,fol))

    if dist[-1] == INF:
        print(-1)
    else:
        print(dist[-1])

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.buffer.readline
import numpy as np
from operator import itemgetter

def main():
    N,M = map(int,input().split())
    root = [list(map(int,input().split())) for _ in range(M)]
    
    root.sort(key=itemgetter(0))
    d = [10**18 for _ in range(N)]
    d[0] = 0
    d = np.array(d)
    for l,r,c in root:
        if d[l-1] == 10**18:
            print(-1)
            exit()
        else:
            d[l:r] = np.minimum(d[l:r],d[l-1]+c)
            
    print(d[-1])

if __name__ == "__main__":
    main()

Fixed submission:
import sys
input = sys.stdin.readline
import heapq

def main():
    N,M = map(int,input().split())
    INF = 10**15
    root = [[] for _ in range(N)]
    for i in range(N-1):
        root[i+1].append((0,i))
    for _ in range(M):
        l,r,c = map(int,input().split())
        root[l-1].append((c,r-1))
    
    dist = [INF for _ in range(N)]
    q = [(0,0)]
    dist[0] = 0
    while q:
        d,now = heapq.heappop(q)
        if dist[now] < d:
            continue
        for cost,fol in root[now]:
            _d = d+cost
            if dist[fol] > _d:
                dist[fol] = _d
                heapq.heappush(q,(_d,fol))

    if dist[-1] == INF:
        print(-1)
    else:
        print(dist[-1])

if __name__ == "__main__":
    main()