Problem p03305 (python)

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

n,m,s,t = map(int,input().split())


links_e = [[] for _ in range(n+1)]
links_s = [[] for _ in range(n+1)]
for _ in range(m):
    u,v,a,b = map(int, input().split())
    links_e[u].append((a,v))
    links_e[v].append((a,u))
    links_s[u].append((b,v))
    links_s[v].append((b,u))

# dijkstra
import heapq
def dijkstra(links, start, n):
    inf = 10**10
    d = [inf] * (n+1)
    d[start] = 0
    hq = []
    used = set()
    used.add(start)
    for i in links[start]:
        heapq.heappush(hq, i)
    while(hq):
        cost,i = heapq.heappop(hq)
        if( i in used):
            continue
        d[i] = cost
        used.add(i)
        for tmp in links[i]:
            cost_next, j = tmp
            if(not j in used):
                heapq.heappush(hq, (cost+cost_next, j))
    return d

d_e = dijkstra(links_e, s, n)
d_s = dijkstra(links_s, t, n)

ans = [0] * (n+1)
min_cost = 10**15
for i in range(n,0,-1):
    min_cost = min(min_cost, d_e[i]+d_s[i])
    ans[i] = min_cost

for i in range(1,n+1):
    print(10**15 - ans[i])

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import dijkstra

n,m,s,t = map(int,input().split())

row = []
col = []
data_e = []
data_s = []
for _ in range(m):
    u,v,a,b = map(int, input().split())
    row.append(u)
    row.append(v)
    col.append(v)
    col.append(u)
    data_e.append(a)
    data_e.append(a)
    data_s.append(b)
    data_s.append(b)

graph_e = csr_matrix((data_e, (row,col)), shape=(n+1, n+1))
graph_s = csr_matrix((data_s, (row,col)), shape=(n+1, n+1))

d_e = dijkstra(csgraph=graph_e, directed=False, indices=s)
d_s = dijkstra(csgraph=graph_s, directed=False, indices=t)

ans = [0] * (n+1)
min_cost = 10**15
for i in range(n,0,-1):
    min_cost = min(min_cost, d_e[i]+d_s[i])
    ans[i] = min_cost

for i in range(1,n+1):
    print(int(10**15 - ans[i]))

Buggy submission (verdict: Runtime Error):
n,m,s,t = map(int,input().split())
uvab = [list(map(int,input().split())) for _ in range(m)]

# import
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix

cost_e = np.zeros((n,n))
cost_s = np.zeros((n,n))

for i in uvab:
    u,v,a,b = i
    cost_e[u-1][v-1] = a
    cost_s[u-1][v-1] = b
    cost_e[v-1][u-1] = a
    cost_s[v-1][u-1] = b

csr_e = csr_matrix(cost_e)
csr_s = csr_matrix(cost_s)

# en = shortest_path(csr_e, indices=s-1 ,method='D')
# sn = shortest_path(csr_s, indices=t-1 ,method='D')
en = dijkstra(csr_e, indices=s-1)
sn = dijkstra(csr_s, indices=t-1)


ans = [10**15] * n
min_ = en[n-1] + sn[n-1]
for i in range(n-1, -1, -1):
    tmp = en[i] + sn[i]
    min_ = min(min_, tmp)
    ans[i] -= min_

for i in ans:
    print(int(i))

Buggy submission (verdict: Runtime Error):
n,m,s,t = map(int,input().split())
uvab = [list(map(int,input().split())) for _ in range(m)]

# import
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix

inf = np.inf

cost_e = np.zeros((n,n))
cost_s = np.zeros((n,n))

for i in uvab:
    u,v,a,b = i
    cost_e[u-1][v-1] = a
    cost_s[u-1][v-1] = b
    cost_e[v-1][u-1] = a
    cost_s[v-1][u-1] = b

csr_e = csr_matrix(cost_e)
csr_s = csr_matrix(cost_s)

en = shortest_path(csr_e, indices=s-1 ,method='D')
sn = shortest_path(csr_s, indices=t-1 ,method='D')

ans = [10**15] * n
min_ = en[n-1] + sn[n-1]
for i in range(n-1, -1, -1):
    tmp = en[i] + sn[i]
    min_ = min(min_, tmp)
    ans[i] -= min_

for i in ans:
    print(int(i))