結果

問題 No.1 道のショートカット
ユーザー こるこる
提出日時 2017-01-03 15:26:30
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,006 bytes
コンパイル時間 115 ms
コンパイル使用メモリ 10,876 KB
実行使用メモリ 9,828 KB
最終ジャッジ日時 2023-09-22 12:53:59
合計ジャッジ時間 3,209 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
9,116 KB
testcase_01 AC 25 ms
9,108 KB
testcase_02 AC 23 ms
9,100 KB
testcase_03 AC 23 ms
9,108 KB
testcase_04 AC 23 ms
9,036 KB
testcase_05 AC 23 ms
9,268 KB
testcase_06 AC 22 ms
9,160 KB
testcase_07 AC 23 ms
9,164 KB
testcase_08 AC 40 ms
9,496 KB
testcase_09 AC 27 ms
9,472 KB
testcase_10 AC 36 ms
9,432 KB
testcase_11 AC 50 ms
9,364 KB
testcase_12 AC 98 ms
9,828 KB
testcase_13 WA -
testcase_14 AC 23 ms
9,176 KB
testcase_15 AC 23 ms
9,312 KB
testcase_16 AC 24 ms
9,344 KB
testcase_17 AC 23 ms
9,284 KB
testcase_18 AC 24 ms
9,168 KB
testcase_19 AC 24 ms
9,436 KB
testcase_20 AC 28 ms
9,192 KB
testcase_21 AC 24 ms
9,236 KB
testcase_22 AC 24 ms
9,340 KB
testcase_23 AC 83 ms
9,436 KB
testcase_24 AC 78 ms
9,316 KB
testcase_25 AC 32 ms
9,424 KB
testcase_26 AC 28 ms
9,160 KB
testcase_27 AC 72 ms
9,368 KB
testcase_28 AC 23 ms
9,260 KB
testcase_29 AC 40 ms
9,556 KB
testcase_30 AC 26 ms
9,336 KB
testcase_31 AC 36 ms
9,240 KB
testcase_32 AC 48 ms
9,500 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 25 ms
9,280 KB
testcase_36 AC 30 ms
9,412 KB
testcase_37 AC 26 ms
9,368 KB
testcase_38 AC 23 ms
9,132 KB
testcase_39 AC 24 ms
9,252 KB
testcase_40 AC 24 ms
9,332 KB
testcase_41 AC 24 ms
9,140 KB
testcase_42 AC 23 ms
9,116 KB
testcase_43 AC 23 ms
9,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
import queue

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+1)]

def fun(index,cost):
    if dp[index][cost] != -1:
        return dp[index][cost]

    if cost<0:
        return math.inf

    if index==n-1:
        return 0

    mini=math.inf
    for to in range(len(nodes[index].edges_to)):
        mini=min(fun(nodes[index].edges_to[to],cost-nodes[index].edges_cost[to])+nodes[index].edges_minute[to],mini)
    dp[index][cost]=mini
    return mini

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