結果

問題 No.2387 Yokan Factory
ユーザー CyanmondCyanmond
提出日時 2023-07-21 21:55:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 510 ms / 5,000 ms
コード長 1,505 bytes
コンパイル時間 2,317 ms
コンパイル使用メモリ 214,828 KB
実行使用メモリ 15,540 KB
最終ジャッジ日時 2023-10-21 21:56:10
合計ジャッジ時間 7,966 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 263 ms
15,540 KB
testcase_16 AC 176 ms
14,512 KB
testcase_17 AC 402 ms
14,536 KB
testcase_18 AC 294 ms
12,980 KB
testcase_19 AC 308 ms
10,488 KB
testcase_20 AC 249 ms
9,616 KB
testcase_21 AC 494 ms
12,556 KB
testcase_22 AC 229 ms
9,064 KB
testcase_23 AC 338 ms
10,400 KB
testcase_24 AC 155 ms
9,640 KB
testcase_25 AC 186 ms
7,444 KB
testcase_26 AC 415 ms
11,284 KB
testcase_27 AC 510 ms
12,172 KB
testcase_28 AC 4 ms
4,348 KB
testcase_29 AC 5 ms
4,348 KB
testcase_30 AC 4 ms
4,348 KB
testcase_31 AC 4 ms
4,348 KB
testcase_32 AC 3 ms
4,348 KB
testcase_33 AC 3 ms
4,348 KB
testcase_34 AC 5 ms
4,348 KB
testcase_35 AC 4 ms
4,348 KB
testcase_36 AC 3 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
// #include "atcoder/modint"

using i64 = long long;
// using Fp = atcoder::modint998244353;
constexpr i64 inf = 1ll << 60;

struct Edge {
    int to;
    i64 cost;
    i64 width;
};

int main() {
    int N, M;
    i64 X;
    std::cin >> N >> M >> X;
    std::vector<int> U(M), V(M);
    std::vector<i64> A(M), B(M);
    std::vector<std::vector<Edge>> graph(N);
    for (int i = 0; i < M; ++i) {
        std::cin >> U[i] >> V[i];
        --U[i], --V[i];
        std::cin >> A[i] >> B[i];
        graph[U[i]].push_back({V[i], A[i], B[i]});
        graph[V[i]].push_back({U[i], A[i], B[i]});
    }

    i64 ok = -1, ng = 1ll << 60;

    auto calcDist = [&](i64 m) {
        std::vector<i64> dist(N, inf);
        dist[0] = 0;
        std::priority_queue<std::pair<i64, int>, std::vector<std::pair<i64, int>>, std::greater<std::pair<i64, int>>> pq;
        pq.push({0, 0});
        while (not pq.empty()) {
            const auto [nd, f] = pq.top();
            pq.pop();
            if (nd > dist[f]) continue;
            for (const auto &[t, c, w] : graph[f]) {
                if (w < m) continue;
                if (dist[t] > dist[f] + c) {
                    dist[t] = dist[f] + c;
                    pq.push({dist[t], t});
                }
            }
        }
        return dist[N - 1];
    };

    while (ng - ok > 1) {
        const auto mid = (ok + ng) / 2;
        if (calcDist(mid) <= X) ok = mid;
        else ng = mid;
    }
    std::cout << ok << std::endl;
}
0