結果

問題 No.1607 Kth Maximum Card
ユーザー snow39snow39
提出日時 2021-07-16 22:31:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 744 ms / 3,500 ms
コード長 1,984 bytes
コンパイル時間 1,171 ms
コンパイル使用メモリ 115,952 KB
実行使用メモリ 15,652 KB
最終ジャッジ日時 2023-09-20 14:48:23
合計ジャッジ時間 8,765 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 492 ms
15,532 KB
testcase_09 AC 321 ms
13,212 KB
testcase_10 AC 491 ms
15,652 KB
testcase_11 AC 43 ms
5,948 KB
testcase_12 AC 308 ms
12,952 KB
testcase_13 AC 36 ms
4,840 KB
testcase_14 AC 43 ms
5,532 KB
testcase_15 AC 305 ms
12,324 KB
testcase_16 AC 33 ms
4,816 KB
testcase_17 AC 13 ms
4,376 KB
testcase_18 AC 140 ms
9,100 KB
testcase_19 AC 80 ms
6,960 KB
testcase_20 AC 130 ms
7,976 KB
testcase_21 AC 139 ms
8,420 KB
testcase_22 AC 528 ms
14,804 KB
testcase_23 AC 535 ms
14,792 KB
testcase_24 AC 110 ms
6,692 KB
testcase_25 AC 60 ms
5,616 KB
testcase_26 AC 70 ms
5,868 KB
testcase_27 AC 132 ms
7,092 KB
testcase_28 AC 86 ms
6,176 KB
testcase_29 AC 238 ms
9,780 KB
testcase_30 AC 744 ms
14,396 KB
testcase_31 AC 193 ms
9,384 KB
testcase_32 AC 75 ms
8,744 KB
testcase_33 AC 76 ms
8,812 KB
testcase_34 AC 73 ms
8,508 KB
testcase_35 AC 73 ms
8,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

#define mkp make_pair
#define mkt make_tuple
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
template <class T>
void chmin(T &a, const T &b) {
    if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
    if (a < b) a = b;
}

const int INF = 1e9;
const int LIM = 2e5 + 10;

void solve() {
    int N, M, K;
    cin >> N >> M >> K;
    vector<vector<pair<int, int>>> g(N);
    rep(i, M) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        g[a].emplace_back(b, c);
        g[b].emplace_back(a, c);
    }

    auto judge = [&](int lim) -> bool {
        deque<int> DQ;
        vector<int> dist(N, INF);
        DQ.push_front(0);
        dist[0] = 0;
        while (!DQ.empty()) {
            int now = DQ.front();
            DQ.pop_front();

            for (auto [to, w] : g[now]) {
                if (w >= lim) {
                    if (dist[to] > dist[now] + 1) {
                        dist[to] = dist[now] + 1;
                        DQ.push_back(to);
                    }
                } else {
                    if (dist[to] > dist[now]) {
                        dist[to] = dist[now];
                        DQ.push_front(to);
                    }
                }
            }
        }
        if (dist[N - 1] >= K)
            return true;
        else
            return false;
    };

    int up = LIM, dw = 0;
    while (abs(up - dw) > 1) {
        int mid = (up + dw) / 2;
        if (judge(mid))
            dw = mid;
        else
            up = mid;
    }

    cout << dw << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    solve();

    return 0;
}
0