結果

問題 No.1607 Kth Maximum Card
ユーザー kwm_tkwm_t
提出日時 2021-07-17 12:16:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 677 ms / 3,500 ms
コード長 1,725 bytes
コンパイル時間 1,637 ms
コンパイル使用メモリ 172,592 KB
実行使用メモリ 16,288 KB
最終ジャッジ日時 2023-09-21 05:30:20
合計ジャッジ時間 9,258 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,296 KB
testcase_01 AC 5 ms
8,012 KB
testcase_02 AC 4 ms
8,004 KB
testcase_03 AC 4 ms
8,204 KB
testcase_04 AC 4 ms
8,028 KB
testcase_05 AC 4 ms
8,088 KB
testcase_06 AC 3 ms
8,076 KB
testcase_07 AC 4 ms
8,016 KB
testcase_08 AC 425 ms
16,184 KB
testcase_09 AC 300 ms
14,628 KB
testcase_10 AC 438 ms
16,288 KB
testcase_11 AC 57 ms
10,132 KB
testcase_12 AC 287 ms
14,448 KB
testcase_13 AC 46 ms
9,232 KB
testcase_14 AC 57 ms
9,688 KB
testcase_15 AC 256 ms
14,256 KB
testcase_16 AC 45 ms
9,388 KB
testcase_17 AC 18 ms
8,504 KB
testcase_18 AC 159 ms
12,416 KB
testcase_19 AC 101 ms
11,096 KB
testcase_20 AC 141 ms
11,436 KB
testcase_21 AC 156 ms
11,852 KB
testcase_22 AC 378 ms
15,048 KB
testcase_23 AC 395 ms
15,100 KB
testcase_24 AC 137 ms
10,296 KB
testcase_25 AC 86 ms
9,512 KB
testcase_26 AC 99 ms
9,724 KB
testcase_27 AC 146 ms
10,416 KB
testcase_28 AC 118 ms
9,984 KB
testcase_29 AC 251 ms
12,428 KB
testcase_30 AC 677 ms
15,004 KB
testcase_31 AC 226 ms
11,876 KB
testcase_32 AC 82 ms
13,516 KB
testcase_33 AC 81 ms
13,308 KB
testcase_34 AC 80 ms
13,440 KB
testcase_35 AC 80 ms
13,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
//#include "atcoder/all"
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
const int INF = 1e9;
//const long long LINF = 1e18;
//const bool debug = false;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
struct Edge {
	int to, cost;
	Edge(int _to, int _cost) :to(_to), cost(_cost) {}
};
vector<Edge>g[200005];
bool f(int x, int n, int k) {
	deque<int> q;
	vector<int> d(n, INF);
	d[0] = 0;
	q.push_back(0);
	while (!q.empty()) {
		int v = q.front();
		q.pop_front();
		for (auto ng : g[v]) {
			int nv = ng.to;
			if (ng.cost <= x) {
				//0
				if (chmin(d[nv], d[v])) q.push_front(nv);
			}
			else {
				//1
				if (chmin(d[nv], d[v] + 1)) q.push_back(nv);
			}
		}
	}
	return d[n - 1] < k;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, m, k; cin >> n >> m >> k;
	rep(i, m) {
		int v, w, c; cin >> v >> w >> c;
		v--; w--;
		g[v].emplace_back(w, c);
		g[w].emplace_back(v, c);
	}
	int ng = -1;
	int ok = INF;
	while (1 < abs(ok - ng)) {
		int c = (ng + ok) / 2;
		if (f(c, n, k)) ok = c;
		else ng = c;
	}
	cout << ok << endl;
	return 0;
}
0