結果
問題 | No.1 道のショートカット |
ユーザー |
![]() |
提出日時 | 2015-05-01 22:49:04 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 15 ms / 5,000 ms |
コード長 | 1,140 bytes |
コンパイル時間 | 669 ms |
コンパイル使用メモリ | 85,248 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-20 16:13:08 |
合計ジャッジ時間 | 1,982 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 40 |
ソースコード
#include<iostream> #include<fstream> #include<sstream> #include<string> #include<cstdio> #include<cstdlib> #include<cstring> #include<ctime> #include<stack> #include<queue> #include<set> #include<map> #include<vector> #include<list> #include<algorithm> #include<utility> #include<complex> #include<functional> using namespace std; #define LL long long #define V 50 #define E 1500 #define M 301 LL dp[V][M]; const LL INF = 1e9; LL from[E], to[E], tim[E], cost[E]; LL v, m, e; void solve(){ for (int i = 0; i < V; i++) for (int j = 0; j < M; j++)dp[i][j] = INF; dp[0][0] = 0; for (int i = 0; i < 51; i++){ for (int j = 0; j < e; j++){ for (LL k = cost[j]; k <= m; k++) dp[to[j]][k] = min(dp[to[j]][k], dp[from[j]][k - cost[j]] + tim[j]); } } } int main(void){ cin >> v >> m >> e; v--; for (int i = 0; i < e; i++){ cin >> from[i]; from[i]--; } for (int i = 0; i < e; i++){ cin >> to[i]; to[i]--; } for (int i = 0; i < e; i++)cin >> cost[i]; for (int i = 0; i < e; i++)cin >> tim[i]; solve(); LL res = INF; for (int i = 0; i <= m; i++) res = min(res, dp[v][i]); cout << ((res==INF)?-1:res) << endl; return 0; }