結果

問題 No.1 道のショートカット
ユーザー 👑 NachiaNachia
提出日時 2020-09-27 11:22:48
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 33 ms / 5,000 ms
コード長 1,053 bytes
コンパイル時間 1,583 ms
コンパイル使用メモリ 173,956 KB
実行使用メモリ 4,948 KB
最終ジャッジ日時 2023-09-27 22:32:30
合計ジャッジ時間 2,926 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 10 ms
4,376 KB
testcase_12 AC 12 ms
4,376 KB
testcase_13 AC 10 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,384 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 33 ms
4,948 KB
testcase_24 AC 30 ms
4,376 KB
testcase_25 AC 5 ms
4,376 KB
testcase_26 AC 3 ms
4,380 KB
testcase_27 AC 21 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 5 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 4 ms
4,376 KB
testcase_32 AC 4 ms
4,380 KB
testcase_33 AC 3 ms
4,376 KB
testcase_34 AC 15 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 3 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

struct Edge { int v, c, d; };

int N, C, M;
int D[50][301];
vector<Edge> E[50];
const int INF = 1000000000;

int main() {
    cin >> N >> C >> M;
    {
        int Ebuf[1500][4]; rep(j, 4) rep(i, M) cin >> Ebuf[i][j];
        rep(i, M) E[Ebuf[i][0] - 1].push_back({ Ebuf[i][1] - 1,Ebuf[i][2],Ebuf[i][3] });
    }

    rep(i, N) rep(j, C + 1) D[i][j] = INF;
    priority_queue<pair<int, pair<int, int>>> Q; Q.push({ 0,{0,C} });
    while (Q.size()) {
        int d = Q.top().first;
        int p = Q.top().second.first;
        int c = Q.top().second.second; Q.pop();
        if (D[p][c] != INF) continue;
        D[p][c] = -d;
        for (Edge& e : E[p]) {
            if (c < e.c) continue;
            Q.push({ d - e.d, {e.v, c - e.c} });
        }
    }

    int ans = INF;
    rep(i, C + 1) ans = min(ans, D[N - 1][i]);
    if (ans == INF) cout << -1 << endl;
    else cout << ans << endl;

    return 0;
}
0