結果

問題 No.1 道のショートカット
コンテスト
ユーザー otsuneko
提出日時 2021-04-24 01:06:36
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
MLE  
実行時間 -
コード長 740 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 421 ms
コンパイル使用メモリ 20,700 KB
実行使用メモリ 1,321,304 KB
最終ジャッジ日時 2026-03-25 16:26:36
合計ジャッジ時間 15,052 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 MLE * 2
other AC * 31 TLE * 5 MLE * 4
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

def dfs(s,y,m):
    global cost_time
    if s == N-1:
        cost_time.append((y,m))
    for to, cost, time in adj[s]:
        if y + cost <= C:
            dfs(to,y+cost,m+time)
                
# 入力の受け取り・隣接リストadjの構築:
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()))

adj = [[] for _ in range(N)]
for i in range(V):
    adj[S[i]-1].append((T[i]-1, Y[i], M[i]))

cost_time = []
dfs(0,0,0)

ans = float("INF")
for cost,time in cost_time:
    if cost <= C:
        ans = min(ans,time)
ans = -1 if ans == float("INF") else ans
print(ans)
0