結果

問題 No.1607 Kth Maximum Card
ユーザー 👑 kmjpkmjp
提出日時 2021-07-16 22:17:29
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 880 ms / 3,500 ms
コード長 1,478 bytes
コンパイル時間 2,825 ms
コンパイル使用メモリ 207,008 KB
実行使用メモリ 16,216 KB
最終ジャッジ日時 2023-09-20 14:28:04
合計ジャッジ時間 10,789 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,092 KB
testcase_01 AC 4 ms
8,124 KB
testcase_02 AC 4 ms
8,096 KB
testcase_03 AC 5 ms
8,124 KB
testcase_04 AC 4 ms
8,088 KB
testcase_05 AC 4 ms
8,132 KB
testcase_06 AC 4 ms
8,028 KB
testcase_07 AC 4 ms
8,092 KB
testcase_08 AC 599 ms
16,204 KB
testcase_09 AC 415 ms
14,648 KB
testcase_10 AC 547 ms
16,216 KB
testcase_11 AC 55 ms
10,020 KB
testcase_12 AC 357 ms
14,396 KB
testcase_13 AC 41 ms
9,280 KB
testcase_14 AC 50 ms
9,772 KB
testcase_15 AC 259 ms
14,260 KB
testcase_16 AC 40 ms
9,488 KB
testcase_17 AC 17 ms
8,580 KB
testcase_18 AC 143 ms
12,416 KB
testcase_19 AC 91 ms
10,940 KB
testcase_20 AC 135 ms
11,544 KB
testcase_21 AC 145 ms
11,888 KB
testcase_22 AC 424 ms
15,124 KB
testcase_23 AC 464 ms
15,124 KB
testcase_24 AC 133 ms
10,456 KB
testcase_25 AC 71 ms
9,572 KB
testcase_26 AC 83 ms
9,832 KB
testcase_27 AC 140 ms
10,532 KB
testcase_28 AC 103 ms
9,976 KB
testcase_29 AC 308 ms
12,352 KB
testcase_30 AC 880 ms
15,036 KB
testcase_31 AC 244 ms
11,844 KB
testcase_32 AC 90 ms
13,616 KB
testcase_33 AC 89 ms
13,564 KB
testcase_34 AC 89 ms
13,496 KB
testcase_35 AC 87 ms
13,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N,M,K;
vector<pair<int,int>> E[202020];
int dp[202020];
int can(int v) {
	int i;
	FOR(i,N) dp[i]=1<<20;
	dp[0]=0;
	deque<int> Q;
	Q.push_back(0);
	while(Q.size()) {
		int cur=Q.front();
		Q.pop_front();
		FORR2(e,c,E[cur]) {
			if(c<v) {
				if(dp[e]>dp[cur]) {
					dp[e]=dp[cur];
					Q.push_front(e);
				}
			}
			else {
				if(dp[e]>dp[cur]+1) {
					dp[e]=dp[cur]+1;
					Q.push_back(e);
				}
			}
		}
		
	}
	return dp[N-1];
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M>>K;
	FOR(i,M) {
		cin>>x>>y>>k;
		E[x-1].push_back({y-1,k});
		E[y-1].push_back({x-1,k});
	}
	int mi=1<<20;
	for(i=19;i>=0;i--) if(can(mi-(1<<i))<K) mi-=1<<i;
	cout<<mi-1<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0