結果

問題 No.1607 Kth Maximum Card
ユーザー merom686merom686
提出日時 2021-07-16 22:37:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,426 bytes
コンパイル時間 2,145 ms
コンパイル使用メモリ 204,896 KB
実行使用メモリ 11,720 KB
最終ジャッジ日時 2023-09-20 14:56:57
合計ジャッジ時間 5,127 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 WA -
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 WA -
testcase_07 AC 2 ms
4,380 KB
testcase_08 WA -
testcase_09 AC 63 ms
9,812 KB
testcase_10 AC 80 ms
10,700 KB
testcase_11 AC 18 ms
4,708 KB
testcase_12 AC 61 ms
10,220 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 15 ms
4,692 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 44 ms
6,868 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

struct Graph {
    struct Vertex { int n, d, c; };
    struct Edge { int i, n; };
    Graph(int n) : v(n, { -1, -1, 1 << 30 }), q(n), n(n), m(0) {}
    void add_edge(int i, int j) {
        e.push_back({ j, v[i].n });
        v[i].n = m;
        m++;
    }
    void bfs(int i0) {
        for (int i = 0; i < n; i++) {
            v[i].d = -1;
        }
        v[i0].d = 0;

        int j0 = 0, j1 = 0;
        q[j1++] = i0;

        while (j0 < j1) {
            int i = q[j0++];
            for (int j = v[i].n; j >= 0; j = e[j].n) {
                Edge &o = e[j];
                if (v[o.i].d >= 0) continue;

                v[o.i].d = v[i].d + 1;
                q[j1++] = o.i;
            }
        }
    }
    vector<Vertex> v;
    vector<Edge> e;
    vector<int> q;
    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);
        g.add_edge(v, u);
        g.v[u].c = min(g.v[u].c, c);
        g.v[v].c = min(g.v[v].c, c);
    }
    g.v[0].c = 0;

    g.bfs(n - 1);
    int r = 1 << 30;
    for (int i = 0; i < n; i++) {
        if (g.v[i].d < k) {
            r = min(r, g.v[i].c);
        }
    }
    cout << r << endl;

    return 0;
}
0