結果
問題 | No.1 道のショートカット |
ユーザー |
![]() |
提出日時 | 2024-02-26 00:23:56 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 6 ms / 5,000 ms |
コード長 | 1,193 bytes |
コンパイル時間 | 2,438 ms |
コンパイル使用メモリ | 212,968 KB |
最終ジャッジ日時 | 2025-02-19 21:32:47 |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 40 |
ソースコード
#include <bits/stdc++.h>using namespace std;#ifdef LOCAL#include "settings/debug.cpp"#define _GLIBCXX_DEBUG#else#define Debug(...) void(0)#endif#define rep(i, n) for (int i = 0; i < (n); ++i)using ll = long long;using ull = unsigned long long;int main() {int n, c, v;cin >> n >> c >> v;vector Graph(n, vector<tuple<int, int, int>>());{vector<int> s(v), t(v), y(v), m(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];rep(i, v) {Graph[--s[i]].push_back({ --t[i], y[i], m[i] });}}constexpr ll INF = 1e18;vector dist(c + 1, vector<ll>(n, INF));dist[0][0] = 0;priority_queue<tuple<ll, int, int>, vector<tuple<ll, int, int>>, greater<>> pq;pq.push({ 0, 0, 0 });while (!pq.empty()) {auto [d, co, v] = pq.top();pq.pop();for (auto [nv, y, m] : Graph[v]) {if (co + y <= c && dist[co + y][nv] > dist[co][v] + m) {dist[co + y][nv] = dist[co][v] + m;pq.push({ dist[co + y][nv], co + y, nv });}}}ll ans = INF;rep(i, c + 1) ans = min(ans, dist[i][n - 1]);cout << (ans == INF ? -1 : ans) << endl;return 0;}