結果
問題 | No.1 道のショートカット |
ユーザー |
![]() |
提出日時 | 2017-01-03 15:48:52 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 123 ms / 5,000 ms |
コード長 | 1,006 bytes |
コンパイル時間 | 149 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 11,264 KB |
最終ジャッジ日時 | 2024-07-20 16:28:41 |
合計ジャッジ時間 | 3,315 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 40 |
ソースコード
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)