結果

問題 No.1607 Kth Maximum Card
ユーザー milanis48663220
提出日時 2021-07-16 22:31:29
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2,966 ms / 3,500 ms
コード長 2,285 bytes
コンパイル時間 1,199 ms
コンパイル使用メモリ 125,952 KB
最終ジャッジ日時 2025-01-23 02:20:29
ジャッジサーバーID
(参考情報)
judge4 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0