結果
問題 | No.1 道のショートカット |
ユーザー |
![]() |
提出日時 | 2014-11-25 19:21:34 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 1,286 bytes |
コンパイル時間 | 1,435 ms |
コンパイル使用メモリ | 166,152 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-20 16:07:19 |
合計ジャッジ時間 | 2,656 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 40 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i,n) repi(i,0,n) #define repi(i,a,b) for(int i=int(a);i<int(b);++i) const int E = 1500; int n, c, v, s[E], t[E], y[E], m[E]; void input() { cin >> n >> c >> v; rep(i, v) cin >> s[i]; rep(i, v) cin >> t[i]; rep(i, v) cin >> y[i]; rep(i, v) cin >> m[i]; } struct edge { int to, cost, dist; edge(int to, int cost, int dist) : to(to), cost(cost), dist(dist) {} }; typedef vector<vector<edge> > graph; graph G; void construct() { G.assign(n, vector<edge>()); rep(i, v) { G[s[i] - 1].emplace_back(t[i] - 1, y[i], m[i]); } } const int N = 50; const int C = 300; const int inf = int(1e9); int dp[N][C + 1]; int solve() { construct(); rep(i, n) rep(j, c + 1) dp[i][j] = inf; dp[0][0] = 0; rep(i, n) rep(j, c + 1) { for (const auto& e : G[i]) { if (j + e.cost > c) continue; dp[e.to][j + e.cost] = min(dp[e.to][j + e.cost], dp[i][j] + e.dist); } } int ans = *min_element(dp[n - 1], dp[n - 1] + c + 1); return ans == inf ? -1 : ans; } int main() { cin.tie(0); ios_base::sync_with_stdio(false); input(); cout << solve() << endl; }