結果

問題 No.1607 Kth Maximum Card
ユーザー ktr216ktr216
提出日時 2021-07-16 23:12:35
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,378 bytes
コンパイル時間 1,548 ms
コンパイル使用メモリ 176,256 KB
実行使用メモリ 16,148 KB
最終ジャッジ日時 2023-09-20 15:39:13
合計ジャッジ時間 6,444 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,616 KB
testcase_01 AC 3 ms
5,724 KB
testcase_02 AC 3 ms
5,780 KB
testcase_03 WA -
testcase_04 AC 3 ms
5,636 KB
testcase_05 AC 3 ms
5,668 KB
testcase_06 WA -
testcase_07 AC 3 ms
5,768 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 AC 64 ms
8,600 KB
testcase_12 RE -
testcase_13 WA -
testcase_14 WA -
testcase_15 RE -
testcase_16 AC 46 ms
7,956 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 RE -
testcase_23 RE -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, l, r) for (int i = (l); i < (r); i++)
using namespace std;

typedef long long ll;

typedef pair<ll, ll> P;
struct edge { ll to, cost; };

const int MAX_V =100000;
const ll INF = 1LL<<60;

int V;
vector<edge> G[MAX_V];
ll d[MAX_V];

void dijkstra(ll s) {
    // greater<P>を指定することでfirstが小さい順に取り出せるようにする
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d + V, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        rep(i,0,G[v].size()) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main() {
    int N, M, K, u, v, c;
    cin >> N >> M >> K;
    V = N;
    vector<int> cmin(N, 1e9);
    rep(i, 0, M) {
        cin >> u >> v >> c;
        u--;
        v--;
        G[u].push_back({v, 1});
        G[v].push_back({u, 1});
        cmin[u] = min(cmin[u], c);
        cmin[v] = min(cmin[v], c);
    }
    dijkstra(N - 1);
    if (d[0] < K) {
        cout << 0 << endl;
        return 0;
    }
    int ans = 1e9;
    rep(i, 0, N) {
        if (d[i] < K) ans = min(ans, cmin[i]);
    }
    cout << ans << endl;
}
0