結果

問題 No.1607 Kth Maximum Card
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-06-10 20:55:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,659 ms / 3,500 ms
コード長 1,493 bytes
コンパイル時間 1,429 ms
コンパイル使用メモリ 120,248 KB
実行使用メモリ 24,888 KB
最終ジャッジ日時 2023-08-31 00:55:02
合計ジャッジ時間 30,154 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2,532 ms
24,316 KB
testcase_09 AC 1,781 ms
20,852 KB
testcase_10 AC 2,383 ms
24,672 KB
testcase_11 AC 307 ms
8,204 KB
testcase_12 AC 1,684 ms
20,072 KB
testcase_13 AC 150 ms
6,744 KB
testcase_14 AC 183 ms
7,700 KB
testcase_15 AC 1,310 ms
20,148 KB
testcase_16 AC 149 ms
7,124 KB
testcase_17 AC 49 ms
4,660 KB
testcase_18 AC 653 ms
15,560 KB
testcase_19 AC 360 ms
10,756 KB
testcase_20 AC 543 ms
12,680 KB
testcase_21 AC 594 ms
13,716 KB
testcase_22 AC 1,761 ms
23,312 KB
testcase_23 AC 1,806 ms
23,256 KB
testcase_24 AC 407 ms
9,892 KB
testcase_25 AC 229 ms
7,616 KB
testcase_26 AC 293 ms
8,596 KB
testcase_27 AC 452 ms
10,392 KB
testcase_28 AC 340 ms
9,012 KB
testcase_29 AC 1,116 ms
15,832 KB
testcase_30 AC 2,659 ms
24,888 KB
testcase_31 AC 955 ms
14,444 KB
testcase_32 AC 325 ms
18,664 KB
testcase_33 AC 341 ms
18,584 KB
testcase_34 AC 331 ms
18,600 KB
testcase_35 AC 334 ms
18,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;

template<typename T> using pq = priority_queue<T, vector<T>, greater<T>>;
using ll = long long;

ll N, M, K;
vector<ll> u, v, c;

bool solve(ll X){
 
    long long A, B, C, start;
    long long from, alt, d;
    pq<pair<long long, long long>> que;
    vector<vector<pair<long long, long long>>> E(N);
    vector<long long> dist(N, 1e18);
    vector<bool> visit(N);
 
    for (int i=0; i < M; i++){
        A = u[i]; B = v[i];
        C = (c[i] > X ? 1 : 0);
        E[A].push_back({B, C});
        E[B].push_back({A, C});
    }
 
    dist[0] = 0;
    que.push({0, 0});
 
    while(!que.empty()){
        tie(d, from) = que.top();
        que.pop();
        if (visit[from]) continue;
        visit[from] = 1;
        for (auto [to, C] : E[from]){
            alt = d + C;
            if (alt < dist[to]){
                dist[to] = alt;
                que.push({dist[to], to});
            }
        }
    }

    return dist[N-1] < K;
}

int main(){
    cin >> N >> M >> K;
    u.resize(M); v.resize(M); c.resize(M);
    for (int i=0; i<M; i++){
        cin >> u[i] >> v[i] >> c[i];
        u[i]--; v[i]--;
    }

    ll l=-1, r=2e5, c;
    while(r-l>1){
        c = (l+r)/2;
        if (solve(c)) r=c;
        else l=c;
    }

    cout << r << endl;
}
0