結果

問題 No.1 道のショートカット
ユーザー sawfish
提出日時 2022-10-16 18:11:14
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
MLE  
実行時間 -
コード長 1,030 bytes
コンパイル時間 758 ms
コンパイル使用メモリ 77,820 KB
実行使用メモリ 814,572 KB
最終ジャッジ日時 2024-06-27 12:53:40
合計ジャッジ時間 7,869 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 18 MLE * 2 -- * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>

using namespace std;

constexpr int INF = 1 << 29;

struct P {
    int pos;
    int cost;
    int elapse;
};

int S[1500];
int T[1500];
int Y[1500];
int M[1500];

int main() {
    int N, C, V;
    cin >> N >> C >> V;

    for (int i = 0; i < V; i++) cin >> S[i];
    for (int i = 0; i < V; i++) cin >> T[i];
    for (int i = 0; i < V; i++) cin >> Y[i];
    for (int i = 0; i < V; i++) cin >> M[i];

    vector<P> G[N + 1];
    for (int i = 0; i < V; i++) {
        G[S[i]].push_back(P{T[i], Y[i], M[i]});
    }


    queue<P> que;
    int ans = INF;

    que.push(P{1, 0, 0});

    while (!que.empty()) {
        auto p = que.front();
        que.pop();
        if (p.pos == N) {
            ans = min(ans, p.elapse);
            continue;
        }
        for (auto q: G[p.pos]) {
            if (C >= p.cost + q.cost) {
                que.push(P{q.pos, p.cost + q.cost, p.elapse + q.elapse});
            }
        }
    }

    cout << (ans != INF ? ans : -1) << endl;
}
0