結果

問題 No.1607 Kth Maximum Card
ユーザー ktr216
提出日時 2021-07-16 23:12:35
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,378 bytes
コンパイル時間 1,475 ms
コンパイル使用メモリ 176,332 KB
実行使用メモリ 16,384 KB
最終ジャッジ日時 2024-07-06 10:44:06
合計ジャッジ時間 6,432 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 5 WA * 18 RE * 10
権限があれば一括ダウンロードができます

ソースコード

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