INF 1e10 map int input split for in range row list map int input split

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
INF = 1e10
N,A,B = map(int, input().split())
W = []
for i in range(N):
row = list(map(int, input().split()))
W.append(row)
for i in range(N):
for j in range(N):
if W[i][j] < 0:
W[i][j] = INF
for k in range(N):
for i in range(N):
for j in range(N):
if W[i][k] + W[k][j] < W[i][j]:
W[i][j] = W[i][k] + W[k][j]
if W[A-1][B-1]==INF or N==0:
print(-1)
else:
print(W[A-1][B-1])