結果

問題 No.1 道のショートカット
ユーザー warashi
提出日時 2015-02-09 11:34:55
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 832 bytes
コンパイル時間 266 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 17,952 KB
最終ジャッジ日時 2024-07-08 03:45:51
合計ジャッジ時間 7,064 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 4 TLE * 1 -- * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
from collections import defaultdict

N = int(input())
C = int(input())
V = int(input())
S = [int(x) for x in input().split()]
T = [int(x) for x in input().split()]
Y = [int(x) for x in input().split()]
M = [int(x) for x in input().split()]
e = defaultdict(list)
for s, t, y, m in zip(S, T, Y, M):
    e[t].append((s, y, m))


def path(e, max_cost, now):
    if now == 1:
        return {0: 0}
    tmp = defaultdict(list)
    for s, y, m in e[now]:
        for cost, time in path(e, max_cost, s).items():
            cost += y
            time += m
            if cost <= max_cost:
                tmp[cost].append(time)
    ret = {}
    for cost, times in tmp.items():
        ret[cost] = min(times)
    return ret

walks = path(e, C, N).values()
if len(walks) == 0:
    print(-1)
else:
    print(min(walks))
0