結果

問題 No.1 道のショートカット
ユーザー HYEA LEE
提出日時 2021-11-04 11:38:56
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 867 bytes
コンパイル時間 3,458 ms
コンパイル使用メモリ 167,424 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-14 09:06:32
合計ジャッジ時間 4,956 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    int N, C, V; cin >> N >> C >> V;
    vector<int> S(V), T(V), Y(V), M(V);
    for(int&x: S) cin >> x;
    for(int&x: T) cin >> x;
    for(int&x: Y) cin >> x;
    for(int&x: M) cin >> x;
    vector<vector<tuple<int, int, int>>>conn(N);
    for(int i=0;i<V;++i) conn[S[i]-1].emplace_back(T[i]-1, Y[i], M[i]);
    vector<vector<bool>> vis(C+1, vector<bool>(N));
    using T3 = tuple<int, int, int>;
    priority_queue<T3, vector<T3>, greater<T3>> Q;
    Q.emplace(0, C, 0);
    while(!Q.empty())
    {
        auto [d, c, v] = Q.top(); Q.pop();
        if(vis[c][v]) continue; else vis[c][v] = true;
        if(v == N-1){ cout << d << endl; return 0; }
        for(auto [u, cc, dd]: conn[v]) if(c >= cc) Q.emplace(d+dd, c-cc, u);
    }
    cout << -1 << endl;
}
0