結果

問題 No.1607 Kth Maximum Card
ユーザー rtyurtyu
提出日時 2021-07-16 22:07:21
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 713 ms / 3,500 ms
コード長 1,132 bytes
コンパイル時間 683 ms
コンパイル使用メモリ 76,648 KB
実行使用メモリ 16,812 KB
最終ジャッジ日時 2023-09-20 14:10:11
合計ジャッジ時間 8,510 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,988 KB
testcase_01 AC 4 ms
8,108 KB
testcase_02 AC 4 ms
8,056 KB
testcase_03 AC 4 ms
8,116 KB
testcase_04 AC 4 ms
8,104 KB
testcase_05 AC 5 ms
8,048 KB
testcase_06 AC 4 ms
8,112 KB
testcase_07 AC 4 ms
8,220 KB
testcase_08 AC 596 ms
16,532 KB
testcase_09 AC 453 ms
15,228 KB
testcase_10 AC 593 ms
16,812 KB
testcase_11 AC 76 ms
10,104 KB
testcase_12 AC 364 ms
15,120 KB
testcase_13 AC 51 ms
9,164 KB
testcase_14 AC 59 ms
9,552 KB
testcase_15 AC 270 ms
13,980 KB
testcase_16 AC 49 ms
9,444 KB
testcase_17 AC 19 ms
8,456 KB
testcase_18 AC 174 ms
12,560 KB
testcase_19 AC 106 ms
10,780 KB
testcase_20 AC 156 ms
11,356 KB
testcase_21 AC 163 ms
11,660 KB
testcase_22 AC 328 ms
15,296 KB
testcase_23 AC 352 ms
15,088 KB
testcase_24 AC 126 ms
10,260 KB
testcase_25 AC 71 ms
9,576 KB
testcase_26 AC 93 ms
9,888 KB
testcase_27 AC 134 ms
10,532 KB
testcase_28 AC 113 ms
9,920 KB
testcase_29 AC 297 ms
12,192 KB
testcase_30 AC 713 ms
15,024 KB
testcase_31 AC 304 ms
11,852 KB
testcase_32 AC 74 ms
13,520 KB
testcase_33 AC 74 ms
13,304 KB
testcase_34 AC 73 ms
13,580 KB
testcase_35 AC 74 ms
13,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
using namespace std;

int n, k, d[200009], inf = 1000000000;
vector<pair<int, int> > v[200009];
list<pair<int, int> > dq;

bool ps(int l)
{
	for (int i = 1; i <= n; i++)
		d[i] = inf;
	dq.clear();
	dq.push_back(make_pair(1, 0)); 
	d[1] = 0;
	while (!dq.empty()) {
		int hn = dq.front().first, hl = dq.front().second; dq.pop_front();
		if (d[hn] != hl) continue;
		for (int i = 0; i < v[hn].size(); i++) {
			int tn = v[hn][i].first, w = (v[hn][i].second > l) ? 1 : 0;
			if (d[tn] > d[hn] + w) {
				d[tn] = d[hn] + w;
				if (w) dq.push_back(make_pair(tn, d[tn]));
				else dq.push_front(make_pair(tn, d[tn]));
			}
		}
	}
	return (d[n] < k);
}

int bs(int s, int e)
{
	int md = (s + e) / 2;
	while (s < e) {
		if (ps(md)) e = md;
		else s = md + 1;
		md = (s + e) / 2;
	}
	return md;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int m; cin >> n >> m >> k;
	for (int i = 0; i < m; i++) {
		int a, b, w; cin >> a >> b >> w;
		v[a].push_back(make_pair(b, w));
		v[b].push_back(make_pair(a, w));
	}
	cout << bs(0, 200000) << '\n';
	return 0;
}
0