結果

問題 No.1607 Kth Maximum Card
ユーザー trineutrontrineutron
提出日時 2021-07-16 22:39:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 805 ms / 3,500 ms
コード長 1,446 bytes
コンパイル時間 2,368 ms
コンパイル使用メモリ 209,144 KB
実行使用メモリ 15,840 KB
最終ジャッジ日時 2023-09-20 15:00:49
合計ジャッジ時間 11,478 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 490 ms
15,612 KB
testcase_09 AC 400 ms
13,532 KB
testcase_10 AC 510 ms
15,840 KB
testcase_11 AC 74 ms
6,192 KB
testcase_12 AC 353 ms
13,068 KB
testcase_13 AC 55 ms
5,124 KB
testcase_14 AC 70 ms
5,424 KB
testcase_15 AC 419 ms
12,284 KB
testcase_16 AC 62 ms
4,948 KB
testcase_17 AC 21 ms
4,380 KB
testcase_18 AC 235 ms
9,196 KB
testcase_19 AC 139 ms
7,056 KB
testcase_20 AC 193 ms
7,856 KB
testcase_21 AC 224 ms
8,508 KB
testcase_22 AC 646 ms
15,020 KB
testcase_23 AC 654 ms
14,856 KB
testcase_24 AC 148 ms
6,664 KB
testcase_25 AC 80 ms
5,372 KB
testcase_26 AC 108 ms
5,952 KB
testcase_27 AC 186 ms
7,240 KB
testcase_28 AC 128 ms
6,136 KB
testcase_29 AC 273 ms
9,912 KB
testcase_30 AC 805 ms
14,304 KB
testcase_31 AC 287 ms
9,440 KB
testcase_32 AC 155 ms
9,172 KB
testcase_33 AC 157 ms
9,228 KB
testcase_34 AC 178 ms
9,832 KB
testcase_35 AC 177 ms
9,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using graph = vector<vector<pair<int, int>>>;

int main()
{
    int n, m, k;
    cin >> n >> m >> k;
    graph to(n);
    for (int i = 0; i < m; i++)
    {
        int u, v, c;
        cin >> u >> v >> c;
        u--;
        v--;
        to.at(u).emplace_back(v, c);
        to.at(v).emplace_back(u, c);
    }
    auto far = [&](int threshold)
    {
        vector<int> d(n, k);
        deque<pair<int, int>> q;
        q.emplace_front(0, 0);
        while (not q.empty())
        {
            auto [v, d0] = q.front();
            q.pop_front();
            if (d.at(v) <= d0)
            {
                continue;
            }
            d.at(v) = d0;
            for (auto &&[next, cost] : to.at(v))
            {
                int c = cost >= threshold;
                if (d.at(next) <= d0 + c)
                {
                    continue;
                }
                if (c)
                {
                    q.emplace_back(next, d0 + c);
                }
                else
                {
                    q.emplace_front(next, d0);
                }
            }
        }
        return d.at(n - 1) >= k;
    };
    int l = 0, r = 200001;
    while (r - l > 1)
    {
        int mid = (l + r) / 2;
        if (far(mid))
        {
            l = mid;
        }
        else
        {
            r = mid;
        }
    }
    cout << l << endl;
    return 0;
}
0