結果
問題 | No.1 道のショートカット |
ユーザー |
|
提出日時 | 2024-05-06 23:23:13 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 35 ms / 5,000 ms |
コード長 | 953 bytes |
コンパイル時間 | 2,245 ms |
コンパイル使用メモリ | 206,656 KB |
最終ジャッジ日時 | 2025-02-21 11:28:30 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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; }