Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- INF = 1000000
- def green(dist, color):
- green_ = -1
- min_ = INF
- for i, t in enumerate(dist):
- if t < min_ and i not in color:
- min_ = t
- green_ = i
- return green_
- n = int(input())
- d, k = map(int, input().split())
- r = int(input())
- graph = [[(INF, INF, -1)] for x in range(n)]
- for x in range(r):
- s, t1, f, t2 = map(int, input().split())
- graph[s-1].append((t1, t2, f-1))
- v = d - 1
- dist = [INF] * n
- dist[v] = 0
- color = {v}
- while v != -1:
- for t1, t2, f in graph[v]:
- if t1 != INF and t2 != INF and f != -1 and f not in color and dist[v] <= t1 and t2 < dist[f]:
- dist[f] = t2
- v = green(dist, color)
- color.add(v)
- if dist[k-1] == INF:
- print(-1)
- else:
- print(dist[k-1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement