結果
| 問題 |
No.1607 Kth Maximum Card
|
| コンテスト | |
| ユーザー |
snow39
|
| 提出日時 | 2021-07-16 22:31:10 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 381 ms / 3,500 ms |
| コード長 | 1,984 bytes |
| コンパイル時間 | 1,156 ms |
| コンパイル使用メモリ | 113,240 KB |
| 最終ジャッジ日時 | 2025-01-23 02:20:04 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 33 |
ソースコード
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#define mkp make_pair
#define mkt make_tuple
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
template <class T>
void chmin(T &a, const T &b) {
if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
if (a < b) a = b;
}
const int INF = 1e9;
const int LIM = 2e5 + 10;
void solve() {
int N, M, K;
cin >> N >> M >> K;
vector<vector<pair<int, int>>> g(N);
rep(i, M) {
int a, b, c;
cin >> a >> b >> c;
a--;
b--;
g[a].emplace_back(b, c);
g[b].emplace_back(a, c);
}
auto judge = [&](int lim) -> bool {
deque<int> DQ;
vector<int> dist(N, INF);
DQ.push_front(0);
dist[0] = 0;
while (!DQ.empty()) {
int now = DQ.front();
DQ.pop_front();
for (auto [to, w] : g[now]) {
if (w >= lim) {
if (dist[to] > dist[now] + 1) {
dist[to] = dist[now] + 1;
DQ.push_back(to);
}
} else {
if (dist[to] > dist[now]) {
dist[to] = dist[now];
DQ.push_front(to);
}
}
}
}
if (dist[N - 1] >= K)
return true;
else
return false;
};
int up = LIM, dw = 0;
while (abs(up - dw) > 1) {
int mid = (up + dw) / 2;
if (judge(mid))
dw = mid;
else
up = mid;
}
cout << dw << endl;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
solve();
return 0;
}
snow39