結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-01-18 16:17:07 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 21 ms / 5,000 ms |
| コード長 | 2,132 bytes |
| コンパイル時間 | 1,301 ms |
| コンパイル使用メモリ | 125,284 KB |
| 実行使用メモリ | 9,856 KB |
| 最終ジャッジ日時 | 2024-12-14 06:46:36 |
| 合計ジャッジ時間 | 2,970 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
ソースコード
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<numeric>
#include<cstring>
#include<random>
#include<array>
#include<fstream>
#include<iomanip>
#include<list>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include<queue>
/*
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,a,b) for(ll i = a; i < b; ++i)
#define PRI(s) std::cout << s << endl
#define PRIF(v, n) printf("%."#n"f\n", (double)v)
template<typename A, typename B>void mins(A& a, const B& b) { a = min(a, (A)b); };
template<typename A, typename B>void maxs(A& a, const B& b) { a = max(a, (A)b); };
struct node {
vector<ll> link;
vector<ll> dist;
ll d = 1e18;
bool done = false;
};
struct edge {
ll s;
ll t;
ll y;
ll m;
};
int main() {
ll N, C, V; cin >> N >> C >> V;
auto ind = [&](ll n, ll c) {
return n * (C+1) + c;
};
vector<node>nod(N * (C+1));
vector<edge> ed(V);
REP(i, 0, V) cin >> ed[i].s;
REP(i, 0, V) cin >> ed[i].t;
REP(i, 0, V) cin >> ed[i].y;
REP(i, 0, V) cin >> ed[i].m;
REP(i, 0, V) {
REP(c, 0, C + 1) {
if (c + ed[i].y > C) continue;
nod[ind(ed[i].s - 1, c)].link.push_back(ind(ed[i].t - 1, c + ed[i].y));
nod[ind(ed[i].s - 1, c)].dist.push_back(ed[i].m);
}
}
auto cmp = [](auto a, auto b) {return a.first > b.first; };
priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, decltype(cmp)> q{ cmp };
nod[0].d = 0;
q.push({ 0,0 });
while (!q.empty()) {
auto p = q.top();
q.pop();
if (nod[p.second].done) continue;
ll i = p.second;
nod[i].done = true;
REP(j, 0, nod[i].link.size()) {
ll c = nod[i].link[j];
if (nod[c].done) continue;
if (nod[c].d > nod[i].d + nod[i].dist[j]) {
nod[c].d = nod[i].d + nod[i].dist[j];
q.push({ nod[c].d, c });
}
}
}
ll ans = 1e18;
REP(i, 0, C + 1) mins(ans, nod[ind(N - 1, i)].d);
if (ans == (ll)1e18) PRI(-1);
else PRI(ans);
return 0;
}