結果

問題 No.1607 Kth Maximum Card
ユーザー milanis48663220milanis48663220
提出日時 2021-07-16 22:31:29
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3,358 ms / 3,500 ms
コード長 2,285 bytes
コンパイル時間 1,253 ms
コンパイル使用メモリ 129,320 KB
実行使用メモリ 36,364 KB
最終ジャッジ日時 2023-09-20 14:49:12
合計ジャッジ時間 26,456 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 3,358 ms
36,364 KB
testcase_09 AC 158 ms
29,640 KB
testcase_10 AC 202 ms
35,492 KB
testcase_11 AC 37 ms
10,828 KB
testcase_12 AC 151 ms
28,540 KB
testcase_13 AC 202 ms
8,560 KB
testcase_14 AC 250 ms
9,956 KB
testcase_15 AC 1,796 ms
29,740 KB
testcase_16 AC 27 ms
8,520 KB
testcase_17 AC 61 ms
5,184 KB
testcase_18 AC 991 ms
21,960 KB
testcase_19 AC 545 ms
14,692 KB
testcase_20 AC 803 ms
17,592 KB
testcase_21 AC 910 ms
19,160 KB
testcase_22 AC 2,775 ms
35,092 KB
testcase_23 AC 2,712 ms
35,004 KB
testcase_24 AC 623 ms
14,040 KB
testcase_25 AC 320 ms
9,896 KB
testcase_26 AC 367 ms
11,144 KB
testcase_27 AC 634 ms
14,256 KB
testcase_28 AC 501 ms
12,324 KB
testcase_29 AC 105 ms
22,428 KB
testcase_30 AC 3,040 ms
35,712 KB
testcase_31 AC 1,161 ms
21,016 KB
testcase_32 AC 386 ms
22,040 KB
testcase_33 AC 373 ms
22,240 KB
testcase_34 AC 387 ms
22,236 KB
testcase_35 AC 379 ms
21,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

const ll INF = 1e+15;

typedef pair<ll, int> P;

struct edge{
    int to;
    ll cost;
};

vector<ll> dijkstra(int s, vector<vector<edge>> G){
    priority_queue<P, vector<P>, greater<P>> que;
    int n = G.size();
    vector<ll> d(n, 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;
        for(int i = 0; i < G[v].size(); i++){
            edge e = G[v][i];
            if(d[v] + e.cost < d[e.to]){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
    return d;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n, m, k; cin >> n >> m >> k;
    vector<int> u(m), v(m), c(m);
    for(int i = 0; i < m; i++){
        cin >> u[i] >> v[i] >> c[i];
        u[i]--, v[i]--;
    }
    auto judge = [&](int x){
        vector<vector<edge>> g(n);
        for(int i = 0; i < m; i++){
            if(c[i] <= x) {
                g[u[i]].push_back(edge{v[i], 0});
                g[v[i]].push_back(edge{u[i], 0});
            }
            else {
                g[u[i]].push_back(edge{v[i], 1});
                g[v[i]].push_back(edge{u[i], 1});
            }
        }
        auto d = dijkstra(0, g);
        // cout << x << ' ' << d[n-1] << endl;
        return d[n-1] <= k-1;
    };
    if(judge(0)) {
        cout << 0 << endl;
        return 0;
    }
    int l = 0, r = 300000;
    while(r-l > 1){
        int x = (l+r)/2;
        if(judge(x)) r = x;
        else l = x;
    }
    cout << r << endl;
}
0