結果
問題 | No.1 道のショートカット |
ユーザー |
👑 ![]() |
提出日時 | 2020-01-21 01:12:38 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 80 ms / 5,000 ms |
コード長 | 1,033 bytes |
コンパイル時間 | 182 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 71,040 KB |
最終ジャッジ日時 | 2024-07-20 16:45:11 |
合計ジャッジ時間 | 3,590 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 40 |
ソースコード
from collections import deque N = int(input()) C = int(input()) V = int(input()) Sori = list(map(int,input().split())) Tori = list(map(int,input().split())) Yori = list(map(int,input().split())) Mori = list(map(int,input().split())) dic = {} for i in range(V): s = Sori[i]-1 t = Tori[i]-1 y = Yori[i] m = Mori[i] if s not in dic: dic[s] = [] dic[s].append([t,y,m]) lis = [[float("inf")] * (C+1) for i in range(N) ] lis[0][0] = 0 q = deque([]) q.append([0,0]) while len(q) > 0: now = q.popleft() np = now[0] nc = now[1] if np not in dic: continue for i in dic[np]: nexp = i[0] nexc = i[1] dis = i[2] if nc + nexc <= C: if lis[nexp][nc+nexc] > lis[np][nc] + dis: lis[nexp][nc+nexc] = lis[np][nc] + dis q.append([nexp,nc+nexc]) ans = float("inf") #print (lis[-1]) for i in range(C+1): ans = min(ans , lis[-1][i]) if ans == float("inf"): print (-1) else: print (ans)