結果

問題 No.1 道のショートカット
ユーザー こるこる
提出日時 2017-01-03 15:48:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 82 ms / 5,000 ms
コード長 1,006 bytes
コンパイル時間 86 ms
コンパイル使用メモリ 10,852 KB
実行使用メモリ 8,660 KB
最終ジャッジ日時 2023-09-27 22:03:43
合計ジャッジ時間 2,637 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
8,348 KB
testcase_01 AC 16 ms
8,456 KB
testcase_02 AC 15 ms
8,348 KB
testcase_03 AC 15 ms
8,244 KB
testcase_04 AC 15 ms
8,368 KB
testcase_05 AC 15 ms
8,320 KB
testcase_06 AC 14 ms
8,428 KB
testcase_07 AC 14 ms
8,276 KB
testcase_08 AC 28 ms
8,548 KB
testcase_09 AC 18 ms
8,472 KB
testcase_10 AC 25 ms
8,012 KB
testcase_11 AC 39 ms
8,128 KB
testcase_12 AC 77 ms
8,532 KB
testcase_13 AC 73 ms
8,532 KB
testcase_14 AC 15 ms
7,944 KB
testcase_15 AC 15 ms
8,132 KB
testcase_16 AC 15 ms
8,068 KB
testcase_17 AC 14 ms
7,940 KB
testcase_18 AC 15 ms
8,044 KB
testcase_19 AC 15 ms
8,164 KB
testcase_20 AC 19 ms
8,088 KB
testcase_21 AC 15 ms
8,016 KB
testcase_22 AC 15 ms
8,104 KB
testcase_23 AC 69 ms
8,532 KB
testcase_24 AC 64 ms
8,052 KB
testcase_25 AC 23 ms
8,020 KB
testcase_26 AC 18 ms
7,968 KB
testcase_27 AC 57 ms
7,976 KB
testcase_28 AC 15 ms
8,244 KB
testcase_29 AC 30 ms
8,576 KB
testcase_30 AC 17 ms
8,464 KB
testcase_31 AC 25 ms
7,944 KB
testcase_32 AC 36 ms
8,612 KB
testcase_33 AC 24 ms
8,048 KB
testcase_34 AC 82 ms
8,660 KB
testcase_35 AC 16 ms
8,056 KB
testcase_36 AC 21 ms
8,000 KB
testcase_37 AC 17 ms
8,024 KB
testcase_38 AC 15 ms
8,048 KB
testcase_39 AC 15 ms
8,076 KB
testcase_40 AC 15 ms
8,128 KB
testcase_41 AC 14 ms
8,292 KB
testcase_42 AC 14 ms
8,444 KB
testcase_43 AC 14 ms
8,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

class Node:
    def __init__(self):
        self.edges_to=[]
        self.edges_cost=[]
        self.edges_minute=[]

n=int(input())
c=int(input())
v=int(input())
s=[int(i) for i in input().split()]
t=[int(i) for i in input().split()]
y=[int(i) for i in input().split()]
m=[int(i) for i in input().split()]

nodes=[Node() for i in range(n)]

for i in range(len(s)):
    nodes[s[i]-1].edges_to.append(t[i]-1)
    nodes[s[i]-1].edges_cost.append(y[i])
    nodes[s[i]-1].edges_minute.append(m[i])

dp=[[-1 for i in range(c+1)] for j in range(n)]


def fun(index,cost):

    if cost<0:
        return math.inf

    if dp[index][cost] != -1:
        return dp[index][cost]

    if index==n-1:
        ret=0
    else:
        ret=math.inf
        for to in range(len(nodes[index].edges_to)):
            ret=min(fun(nodes[index].edges_to[to],cost-nodes[index].edges_cost[to])+nodes[index].edges_minute[to],ret)
    dp[index][cost]=ret
    return ret

sum=fun(0,c)
print(-1 if sum==math.inf else sum)
0