結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-08-26 01:59:04 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 37 ms / 5,000 ms |
| コード長 | 711 bytes |
| コンパイル時間 | 98 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 11,136 KB |
| 最終ジャッジ日時 | 2024-11-17 10:55:35 |
| 合計ジャッジ時間 | 3,136 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
ソースコード
import heapq as pq
def read_int(): return int(input())
def read_int_list(): return list(map(int, input().split()))
N = read_int()
C = read_int()
V = read_int()
S = read_int_list()
T = read_int_list()
Y = read_int_list()
M = read_int_list()
way_from = {}
way_from = [set() for i in range(N + 1)]
for i in range(V):
way_from[S[i]].add((T[i], Y[i], M[i]))
heap = [(0, 1, 0)]
res = -1
while heap:
time, pos, cost = pq.heappop(heap)
if pos == N:
res = time
break
for next_pos, way_cost, way_time in way_from[pos]:
next_cost = cost + way_cost
if C < next_cost:
continue
pq.heappush(heap, (time + way_time, next_pos, next_cost))
print(res)