結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
commy
|
| 提出日時 | 2018-08-10 23:14:13 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,962 bytes |
| コンパイル時間 | 1,095 ms |
| コンパイル使用メモリ | 90,588 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-08 05:03:52 |
| 合計ジャッジ時間 | 2,279 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 16 WA * 24 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
using namespace std;
typedef long long int lli;
template<typename T>
vector<T> make_v(size_t a, T b) {
return vector<T>(a, b);
}
template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}
struct Edge {
lli t, y, m;
Edge(lli _t, lli _y, lli _m)
: t(_t), y(_y), m(_m) {}
Edge() {}
bool operator>(Edge const &e) const {
return m < e.m;
}
};
int main() {
int N, C, V;
cin >> N >> C >> V;
vector<int> S(V), T(V), Y(V), M(V);
REP(i, 0, V) {
cin >> S[i];
}
REP(i, 0, V) {
cin >> T[i];
}
REP(i, 0, V) {
cin >> Y[i];
}
REP(i, 0, V) {
cin >> M[i];
}
vector<vector<Edge>> G(N);
REP(i, 0, V) {
G[S[i] - 1].push_back(Edge(T[i] - 1, Y[i], M[i]));
}
const lli inf = 1LL << 60;
priority_queue<Edge, vector<Edge>, greater<Edge>> pq;
pq.emplace(0, 0, 0);
auto cost = make_v(N, C + 1, inf);
auto used = make_v(N, C + 1, false);
cost[0][0] = 0;
lli ans = inf;
while (pq.size()) {
auto elem = pq.top();
pq.pop();
if (used[elem.t][elem.y]) continue;
used[elem.t][elem.y] = true;
if (elem.t == N - 1) {
ans = min(ans, elem.m);
continue;
}
for (auto &e : G[elem.t]) {
lli ny = elem.y + e.y;
lli nm = elem.m + e.m;
if (ny > C) {
continue;
}
if (cost[e.t][ny] > nm) {
cost[e.t][ny] = nm;
pq.emplace(e.t, ny, nm);
}
}
}
if (ans == inf) {
ans = -1;
}
cout << ans << endl;
return 0;
}
commy