結果
問題 | No.1 道のショートカット |
ユーザー |
|
提出日時 | 2014-12-08 00:06:40 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,757 bytes |
コンパイル時間 | 866 ms |
コンパイル使用メモリ | 101,072 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-08 03:37:52 |
合計ジャッジ時間 | 2,175 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 36 WA * 4 |
ソースコード
#include <cstdio> #include <iostream> #include <sstream> #include <fstream> #include <iomanip> #include <algorithm> #include <cmath> #include <string> #include <vector> #include <list> #include <queue> #include <stack> #include <set> #include <map> #include <bitset> #include <numeric> #include <limits> #include <climits> #include <cfloat> #include <functional> using namespace std; const int INF = INT_MAX / 2; class Edge { public: int to, cost, time; Edge(int to, int cost, int time){ this->to = to; this->cost = cost; this->time = time; } }; int main() { int n, c, v; cin >> n >> c >> v; vector<int> s(v), t(v), y(v), m(v); for(int i=0; i<v; ++i) cin >> s[i]; for(int i=0; i<v; ++i) cin >> t[i]; for(int i=0; i<v; ++i) cin >> y[i]; for(int i=0; i<v; ++i) cin >> m[i]; vector<vector<Edge> > edges(n); for(int i=0; i<v; ++i){ edges[s[i]-1].push_back(Edge(t[i]-1, y[i], m[i])); edges[t[i]-1].push_back(Edge(s[i]-1, y[i], m[i])); } vector<vector<int> > dp(n, vector<int>(c+1, INF)); dp[0][c] = 0; for(int i=c; i>=0; --i){ for(int j=0; j<n; ++j){ for(unsigned k=0; k<edges[j].size(); ++k){ if(i < edges[j][k].cost) continue; int to = edges[j][k].to; int cost = edges[j][k].cost; dp[to][i-cost] = min(dp[to][i-cost], dp[j][i] + edges[j][k].time); } } } int ret = *min_element(dp[n-1].begin(), dp[n-1].end()); if(ret < INF) cout << ret << endl; else cout << -1 << endl; return 0; }