結果
問題 |
No.1 道のショートカット
|
ユーザー |
|
提出日時 | 2022-01-28 20:03:24 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,265 bytes |
コンパイル時間 | 309 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 73,728 KB |
最終ジャッジ日時 | 2024-12-29 23:44:38 |
合計ジャッジ時間 | 4,063 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 11 WA * 29 |
ソースコード
from heapq import heappush, heappop, heapify import sys input = sys.stdin.readline n = int(input()) c = int(input()) v = int(input()) s = list(map(int, input().split())) t = list(map(int, input().split())) y = list(map(int, input().split())) m = list(map(int, input().split())) g = [[] for _ in range(n)] for i in range(v): s[i] -= 1 t[i] -= 1 g[s[i]].append((m[i], y[i], t[i])) # 時間・コスト・行き先 #print('g:のグラフ') #print(*g, sep='\n') INF = 10 ** 18 dist = [INF] * n # かかる時間 cost = [INF] * n # 必要なコスト dist[0] = 0 cost[0] = 0 q = [(0, 0, 0)] # 時間・コスト・今いる場所 heapify(q) while q: pre_time, pre_cost, pre_ind = heappop(q) for nxt_time, nxt_cost, nxt_ind in g[pre_ind]: if pre_cost != cost[pre_ind]: print('tigauo!',pre_cost, cost[pre_ind]) if dist[nxt_ind] <= dist[pre_ind] + nxt_time: continue if pre_cost + nxt_cost > c: continue dist[nxt_ind] = dist[pre_ind] + nxt_time cost[nxt_ind] = pre_cost + nxt_cost heappush(q, (dist[nxt_ind], cost[nxt_ind], nxt_ind)) #print(dist) #print(cost) #print(q) #print() ##print(dist) #print(cost) print(dist[-1]) if dist[-1] != INF else print(-1)