結果
| 問題 | No.1 道のショートカット |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-05-06 23:23:13 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 953 bytes |
| 記録 | |
| コンパイル時間 | 1,339 ms |
| コンパイル使用メモリ | 223,508 KB |
| 実行使用メモリ | 9,972 KB |
| 最終ジャッジ日時 | 2026-07-04 16:41:15 |
| 合計ジャッジ時間 | 2,836 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N,C,V; cin >> N >> C >> V;
vector<int> S(V),T(V),Y(V),M(V);
for(auto &a : S) cin >> a,a--;
for(auto &a : T) cin >> a,a--;
for(auto &a : Y) cin >> a;
for(auto &a : M) cin >> a;
vector<vector<tuple<int,int,int>>> edge(N);
for(int i=0; i<V; i++) edge.at(S.at(i)).push_back({T.at(i),Y.at(i),M.at(i)});
int inf = 2e9;
vector<vector<int>> dp(N,vector<int>(C+1,inf));
dp.at(0).at(C) = 0;
for(int i=0; i<N; i++) for(int k=1; k<=C; k++){
if(dp.at(i).at(k) == inf) continue;
for(auto [to,cost,time] : edge.at(i)){
if(k < cost) continue;
dp.at(to).at(k-cost) = min(dp.at(to).at(k-cost),dp.at(i).at(k)+time);
}
}
int mint = *min_element(dp.at(N-1).begin(),dp.at(N-1).end());
if(mint == inf) mint = -1;
cout << mint << endl;
}