結果
問題 |
No.1 道のショートカット
|
ユーザー |
|
提出日時 | 2018-02-10 18:51:47 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,705 bytes |
コンパイル時間 | 936 ms |
コンパイル使用メモリ | 97,956 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-08 04:58:31 |
合計ジャッジ時間 | 2,870 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 WA * 1 |
other | AC * 10 WA * 25 RE * 5 |
ソースコード
#include <iostream> #include <stdio.h> #include <stdlib.h> #include <algorithm> #include <math.h> #include <vector> #include <queue> #include <map> #include <utility> using namespace std; int main(void) { int n, c, v; cin >> n >> c >> v; int s[v], t[v], y[v], m[v]; pair<int, int> p1, p2; map<pair<int, int>, pair<int, int> > mp; vector<vector<int> > arr(n + 1); vector<int> cost(n + 1, 0); vector<int> time(n + 1, 0); vector<bool> pass(n + 1, false); 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]; for (int i = 0; i < v; i++) { mp[make_pair(s[i], t[i])] = make_pair(y[i], m[i]); arr[s[i]].push_back(t[i]); } int x = 1; pass[1] = true; while (x != n) { for (int i = 0; i <= arr[x].size(); i++) { if (cost[x] + mp[make_pair(x, arr[x][i])].first <= c) { cost[arr[x][i]] = cost[x] + mp[make_pair(x, arr[x][i])].first; time[arr[x][i]] = time[x] + mp[make_pair(x, arr[x][i])].second; } } pass[x] = true; x = 0; for (int i = 2; i <= n; i++) if (!pass[i]&&time[i]>0) { x = i; break; } if (x == 0) { cout << -1 << endl; return 0; } for (int i = x; i <= n; i++) { if (!pass[i] && time[x] > time[i] && time[i] > 0) x = i; } } cout << time[n] << endl; return 0; }