結果

問題 No.1607 Kth Maximum Card
ユーザー 👑 potato167potato167
提出日時 2021-07-16 22:16:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,544 ms / 3,500 ms
コード長 2,460 bytes
コンパイル時間 2,382 ms
コンパイル使用メモリ 214,884 KB
実行使用メモリ 26,816 KB
最終ジャッジ日時 2023-09-20 14:26:10
合計ジャッジ時間 16,683 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1,544 ms
26,572 KB
testcase_09 AC 1,097 ms
22,492 KB
testcase_10 AC 1,368 ms
26,816 KB
testcase_11 AC 182 ms
8,688 KB
testcase_12 AC 1,043 ms
21,552 KB
testcase_13 AC 71 ms
6,128 KB
testcase_14 AC 74 ms
7,304 KB
testcase_15 AC 569 ms
19,852 KB
testcase_16 AC 58 ms
6,476 KB
testcase_17 AC 25 ms
4,376 KB
testcase_18 AC 280 ms
13,872 KB
testcase_19 AC 144 ms
9,640 KB
testcase_20 AC 291 ms
11,480 KB
testcase_21 AC 281 ms
12,504 KB
testcase_22 AC 799 ms
25,604 KB
testcase_23 AC 777 ms
25,528 KB
testcase_24 AC 206 ms
10,332 KB
testcase_25 AC 96 ms
7,484 KB
testcase_26 AC 124 ms
8,652 KB
testcase_27 AC 255 ms
10,428 KB
testcase_28 AC 181 ms
9,076 KB
testcase_29 AC 543 ms
16,188 KB
testcase_30 AC 1,234 ms
24,752 KB
testcase_31 AC 549 ms
14,816 KB
testcase_32 AC 78 ms
11,172 KB
testcase_33 AC 77 ms
11,428 KB
testcase_34 AC 77 ms
11,364 KB
testcase_35 AC 76 ms
11,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll I=1167167167167167167;
ll Q=1e9+7;
#define rep(i,a) for (ll i=0;i<a;i++)
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
template<class T> void print_tate(vector<T> &v) {rep(i,v.size()) cout<<v[i]<<"\n";}
void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";}

using len_type=int;
struct edge{
    int to;
    len_type length;
};

len_type dijkstra_movement(edge e,int from,len_type t){
    return t+e.length;
}

//距離INF=1167167167167167167
vector<len_type> dijkstra(vector<vector<edge>> &G,int start){
    int M=G.size();
    assert(M>start&&start>=0);
    vector<len_type> seen(M,100100100);
    seen[start]=0;
    priority_queue<pair<len_type,int>,vector<pair<len_type,int>>,greater<pair<len_type,int>>> pq;
    pq.push({0,start});
    while(!pq.empty()){
        len_type time;
        int ver;
        tie(time,ver)=pq.top();
        pq.pop();
        if(seen[ver]<time) continue;
        for(edge x:G[ver]){
            len_type T=dijkstra_movement(x,ver,time);
            if(T<seen[x.to]){
                pq.push({T,x.to});
                seen[x.to]=T;
            }
        }
    }
    return seen;
}


//おちこんだりもしたけれど、私はげんきです。
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int N,M,K;
	cin>>N>>M>>K;
	vector<vector<edge>> G(N);
	vector<vector<int>> m(N);
	rep(i,M){
		int a,b,c;
		cin>>a>>b>>c;
		a--,b--;
		G[a].push_back({b,c});
		G[b].push_back({a,c});
		m[a].push_back(c);
		m[b].push_back(c);
	}
	int l=-1,r=200200;
	while(r-l>1){
		int D=(l+r)/2;
		rep(i,N){
			rep(j,G[i].size()){
				if(m[i][j]>D) G[i][j].length=1;
				else G[i][j].length=0;
			}
		}
		auto seen=dijkstra(G,0);
		if(seen[N-1]<K) r=D;
		else l=D;
	}
	cout<<r<<endl;
}
0