結果

問題 No.1 道のショートカット
コンテスト
ユーザー Navier_Boltzmann
提出日時 2022-10-10 08:30:00
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 53 ms / 5,000 ms
コード長 897 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 140 ms
コンパイル使用メモリ 85,836 KB
実行使用メモリ 73,804 KB
最終ジャッジ日時 2026-03-10 02:09:35
合計ジャッジ時間 3,274 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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)
    
0