結果
問題 | No.1607 Kth Maximum Card |
ユーザー |
![]() |
提出日時 | 2021-09-20 17:12:20 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2,093 ms / 3,500 ms |
コード長 | 1,337 bytes |
コンパイル時間 | 2,755 ms |
コンパイル使用メモリ | 204,696 KB |
最終ジャッジ日時 | 2025-01-24 16:03:26 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define ALL(v) (v).begin(),(v).end() using ll=long long int; const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12; template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;} template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;} int main(){ int n,m,k; cin>>n>>m>>k; using P=pair<int,int>; vector g(n,vector<P>()); rep(_,0,m){ int x,y,c; cin>>x>>y>>c; x--; y--; g[x].push_back({y,c}); g[y].push_back({x,c}); } int L=0,R=201010; while(R-L>1){ int mid=(L+R)>>1; vector h(n,vector<P>()); rep(i,0,n)for(auto& [to,c]:g[i]){ if(c<mid){ h[i].push_back({to,0}); } else{ h[i].push_back({to,1}); } } vector<int> dist(n,inf); dist[0]=0; priority_queue<P,vector<P>,greater<P>> pq; pq.push({0,0}); while(!pq.empty()){ auto [d,v]=pq.top(); pq.pop(); if(dist[v]!=d)continue; for(auto& [to,c]:h[v])if(chmin(dist[to],d+c)){ pq.push({dist[to],to}); } } if(dist[n-1]<=k-1)R=mid; else L=mid; } cout<<L<<'\n'; return 0; }