/*
二分答案
若 Li > mid, Ri = 1;否则 Ri = 0.
check():在以 R 为边权的新图中 1 至 N 的最短路若<=K,返回 1;否则返回 0
时间复杂度:
logL * NlogN=20*1000*10=200000
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 1500, M = 10050;
typedef pair<int, int> pa;
struct Edge {
int u, v, w;
} e[M];
int n, m, k, R[M], di[N], bk[N];
vector<pa> E[N];
inline int getDi() {
for (int i = 1; i <= n; ++i) {
E[i].clear();
}
for (int i = 1; i <= m; ++i) {
E[e[i].u].push_back({e[i].v, R[i]});
E[e[i].v].push_back({e[i].u, R[i]});
}
memset(bk, 0, sizeof bk);
memset(di, 0x3f, sizeof di); di[1] = 0;
priority_queue<pa, vector<pa>, greater<pa> > q;
q.push({0, 1});
while (q.size()) {
int u = q.top().second; q.pop();
if (bk[u]) continue;
else bk[u] = 1;
for (int i = 0; i < E[u].size(); ++i) {
int v = E[u][i].first, w = E[u][i].second;
if (di[v] > di[u] + w) q.push({di[v] = di[u] + w, v});
}
}
return di[n];
}
inline bool check(int co) {
for (int i = 1; i <= m; ++i)
if (e[i].w > co) R[i] = 1;
else R[i] = 0;
int res = getDi();
if (res <= k) return 1;
return 0;
}
signed main() {
cin >> n >> m >> k;
for (int i = 1; i <= m; ++i)
cin >> e[i].u >> e[i].v >> e[i].w;
int l = 0, r = 1e6 + 5, mid;
while (l < r) {
mid = l + r >> 1;
if (check(mid)) r = mid;
else l = mid + 1;
}
if (l == 1e6 + 5) puts("-1");
else cout << l;
return 0;
}
哥,优点看不懂,可以写一下注释吗 hah,帮帮我这个弱鸡吧。尤其是checkHa函数中哪个R[i]有什么用,好难挖