Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def green(dist, color):
- green_ = -1
- minimum = 1000
- for i, t in enumerate(dist):
- if t < minimum and i not in color:
- minimum = t
- green_ = i
- return green_
- n, s, f = map(int, input().split())
- graph = [0] * n
- for i in range(n):
- graph[i] = list(map(int, input().split()))
- v = s - 1
- dist = [1000] * n
- color = {v}
- dist[v] = 0
- while v != -1:
- for j, dw in enumerate(graph[v]):
- if dw > 0 and j not in color and dist[v] + dw < dist[j]:
- dist[j] = dist[v] + dw
- v = green(dist, color)
- color.add(v)
- if dist[f-1] == 1000:
- print(-1)
- else:
- print(dist[f-1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement