結果

問題 No.1607 Kth Maximum Card
ユーザー merom686merom686
提出日時 2021-07-16 22:51:33
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 365 ms / 3,500 ms
コード長 1,713 bytes
コンパイル時間 2,147 ms
コンパイル使用メモリ 205,884 KB
実行使用メモリ 12,512 KB
最終ジャッジ日時 2023-09-20 15:15:37
合計ジャッジ時間 7,447 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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,376 KB
testcase_04 AC 2 ms
4,376 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 206 ms
11,552 KB
testcase_09 AC 133 ms
10,976 KB
testcase_10 AC 243 ms
11,520 KB
testcase_11 AC 29 ms
5,052 KB
testcase_12 AC 162 ms
11,168 KB
testcase_13 AC 27 ms
4,876 KB
testcase_14 AC 33 ms
5,028 KB
testcase_15 AC 150 ms
11,388 KB
testcase_16 AC 30 ms
4,900 KB
testcase_17 AC 10 ms
4,380 KB
testcase_18 AC 107 ms
10,368 KB
testcase_19 AC 64 ms
6,624 KB
testcase_20 AC 82 ms
6,672 KB
testcase_21 AC 93 ms
7,400 KB
testcase_22 AC 180 ms
11,608 KB
testcase_23 AC 181 ms
12,512 KB
testcase_24 AC 77 ms
5,240 KB
testcase_25 AC 42 ms
5,016 KB
testcase_26 AC 55 ms
5,112 KB
testcase_27 AC 79 ms
6,688 KB
testcase_28 AC 63 ms
5,216 KB
testcase_29 AC 127 ms
7,040 KB
testcase_30 AC 365 ms
10,960 KB
testcase_31 AC 132 ms
7,180 KB
testcase_32 AC 99 ms
9,744 KB
testcase_33 AC 165 ms
9,964 KB
testcase_34 AC 145 ms
9,380 KB
testcase_35 AC 183 ms
10,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

template <class T, class F>
T LowerBound(T i0, T i1, F f) {
    while (i0 < i1) {
        T i = i0 + (i1 - i0) / 2;
        if (f(i)) i1 = i; else i0 = i + 1;
    }
    return i0;
}

int c0;

struct Graph {
    static constexpr int INF = 1 << 30;
    struct Vertex { int n, c; };
    struct Edge { int i, n, c; };
    Graph(int n) : v(n, { -1, INF }), n(n), m(0) {}
    void add_edge(int i, int j, int c) {
        e.push_back({ j, v[i].n, c });
        v[i].n = m;
        m++;
    }
    void bfs01(int s, int t) {
        vector<int> st[2];
        st[0].push_back(s);
        for (int i = 0; i < n; i++) v[i].c = INF;
        v[s].c = 0;
        while (!st[0].empty() || (swap(st[0], st[1]), !st[0].empty())) {
            int i = st[0].back(); st[0].pop_back();
            if (i == t) break;
            for (int j = v[i].n; j >= 0; j = e[j].n) {
                Edge &o = e[j];
                int oc = o.c > c0;
                int c = v[i].c + oc;
                if (c < v[o.i].c) {
                    v[o.i].c = c;
                    st[oc].push_back(o.i);
                }
            }
        }
    }
    vector<Vertex> v;
    vector<Edge> e;
    int n, m;
};

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

    int n, m, k;
    cin >> n >> m >> k;

    Graph g(n);
    for (int i = 0; i < m; i++) {
        int u, v, c;
        cin >> u >> v >> c;
        u--; v--;

        g.add_edge(u, v, c);
        g.add_edge(v, u, c);
    }

    auto c = LowerBound<int>(0, (int)2e5, [&](auto c) {
        c0 = c;
        g.bfs01(0, n - 1);
        return g.v[n - 1].c < k;
    });
    cout << c << endl;

    return 0;
}
0