Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def dijkstra(G):
- for i in my_list[G]:
- if i[2] < time[i[0]]:
- time[i[0]] = i[2]
- qeueu.append(i[0])
- while qeueu:
- first_el = qeueu.pop(0)
- for i in my_list[first_el]:
- if i[1] >= time[first_el] and i[2] < time[i[0]]:
- time[i[0]] = i[2]
- qeueu.append(i[0])
- N = int(input())
- d, v = map(int, input().split())
- d -= 1
- v -= 1
- R = int(input())
- my_list = [list() for _ in range(N)]
- for i in range(R):
- line = list(map(int, input().split()))
- my_list[line[0] - 1].append([line[2] - 1, line[1], line[3]])
- time = [10 ** 100] * N
- qeueu = list()
- dijkstra(d)
- if time[v] == 10 ** 10:
- print(-1)
- else:
- print(time[v])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement