INF 30000 map int input split INF for in range list map int input spli

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
INF = 30000
n, m = map(int, input().split())
w = [0] * m
d = [INF] * n
d[0] = 0
for i in range(m):
w[i] = list(map(int, input().split()))
for k in range (n-1):
for j in range(m):
if d[w[j][0]-1] != INF:
if d[w[j][1]-1] > d[w[j][0]-1] + w[j][2]:
d[w[j][1]-1] = d[w[j][0]-1] + w[j][2]
print(*d)