結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-10-10 08:30:00 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 81 ms / 5,000 ms |
| コード長 | 897 bytes |
| コンパイル時間 | 184 ms |
| コンパイル使用メモリ | 82,408 KB |
| 実行使用メモリ | 72,808 KB |
| 最終ジャッジ日時 | 2024-06-24 04:12:40 |
| 合計ジャッジ時間 | 4,462 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
ソースコード
from collections import *
from itertools import *
from functools import *
from heapq import *
import sys,math
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
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()))
INF = (1<<60)
dp = [[INF]*(C+2) for _ in range(N)]
e = [[] for _ in range(N)]
for i in range(V):
s,t,y,m = S[i],T[i],Y[i],M[i]
s -= 1
t -= 1
e[s].append((t,y,m))
e[t].append((s,y,m))
dp[0][0] = 0
def f(x):
return min(x,C+1)
for i in range(N-1):
for v,y,m in e[i]:
for j in range(C+1):
dp[v][f(j+y)] = min(dp[v][f(j+y)],dp[i][j]+m)
ans = min(dp[-1][:C+1])
if ans==INF:
print(-1)
else:
print(ans)