結果
問題 | No.1607 Kth Maximum Card |
ユーザー | milanis48663220 |
提出日時 | 2021-07-16 22:34:14 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 3,024 ms / 3,500 ms |
コード長 | 2,359 bytes |
コンパイル時間 | 1,342 ms |
コンパイル使用メモリ | 129,024 KB |
実行使用メモリ | 38,824 KB |
最終ジャッジ日時 | 2023-09-20 14:53:55 |
合計ジャッジ時間 | 25,232 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 2 ms
4,380 KB |
testcase_03 | AC | 2 ms
4,380 KB |
testcase_04 | AC | 2 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,477 ms
36,200 KB |
testcase_09 | AC | 141 ms
29,192 KB |
testcase_10 | AC | 181 ms
35,324 KB |
testcase_11 | AC | 32 ms
10,764 KB |
testcase_12 | AC | 129 ms
28,220 KB |
testcase_13 | AC | 183 ms
8,196 KB |
testcase_14 | AC | 255 ms
9,976 KB |
testcase_15 | AC | 1,924 ms
30,012 KB |
testcase_16 | AC | 26 ms
8,588 KB |
testcase_17 | AC | 54 ms
5,412 KB |
testcase_18 | AC | 1,032 ms
21,776 KB |
testcase_19 | AC | 486 ms
14,580 KB |
testcase_20 | AC | 693 ms
17,412 KB |
testcase_21 | AC | 872 ms
19,280 KB |
testcase_22 | AC | 2,559 ms
35,140 KB |
testcase_23 | AC | 2,809 ms
35,232 KB |
testcase_24 | AC | 513 ms
13,620 KB |
testcase_25 | AC | 286 ms
9,908 KB |
testcase_26 | AC | 342 ms
10,944 KB |
testcase_27 | AC | 581 ms
13,748 KB |
testcase_28 | AC | 467 ms
11,904 KB |
testcase_29 | AC | 107 ms
22,452 KB |
testcase_30 | AC | 3,024 ms
38,824 KB |
testcase_31 | AC | 1,235 ms
20,676 KB |
testcase_32 | AC | 401 ms
22,004 KB |
testcase_33 | AC | 381 ms
22,052 KB |
testcase_34 | AC | 407 ms
22,124 KB |
testcase_35 | AC | 393 ms
22,076 KB |
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <set> #include <map> #include <tuple> #include <cmath> #include <numeric> #include <functional> #include <cassert> #include <deque> #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){ deque<P> que; int n = G.size(); vector<ll> d(n, INF); d[s] = 0; que.push_back(P(0, s)); while(!que.empty()){ P p = que.front();que.pop_front(); 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; if(e.cost == 0) que.push_front(P(d[e.to], e.to)); else que.push_back(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; }