huoguo_fy @ 2023-08-24 20:43:10
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define xx first
#define yy second
typedef pair<int, int> PII;
const int inf = 0x3f3f3f3f3f3f3f3f;
const int N = 1e5 + 10;
int f[N], n, m, k, x, T;
int w[N], e[N], ne[N], idx, h[N];
int l, r, dis[N], vis[N];
priority_queue<PII, vector<PII>, greater<PII>> q;
void add(int a, int b, int c)
{
e[idx] = b, ne[idx] = h[a], w[idx] = c, h[a] = idx++;
}
void dijkstra(int maxn)
{
for (int i = 1; i <= n; i++)
{
dis[i] = inf;
vis[i] = 0;
}
dis[1] = 0;
while (q.size())
q.pop();
q.push({dis[1], 1});
while (q.size())
{
auto t = q.top();
q.pop();
int u = q.top().yy;
if (vis[u])
continue;
vis[u] = 1;
for (int i = h[u]; ~i; i = ne[i])
{
int j = e[i];
if (f[j] > maxn)
continue;
if (dis[j] > w[i] + dis[u])
{
dis[j] = w[i] + dis[u];
q.push({dis[j], j});
}
}
}
}
signed main()
{
int b;
memset(h, -1, sizeof h);
cin >> n >> m >> b;
for (int i = 1; i <= n; i++)
{
cin >> f[i];
r = max(r, f[i]);
}
l = max(f[1], f[n]);
for (int i = 1; i <= m; i++)
{
int a, b, c;
cin >> a >> b >> c;
add(a, b, c), add(b, a, c);
}
while (l < r)
{
int mid = (l + r) >> 1;
dijkstra(mid);
if (dis[n] > b)
l = mid + 1; // 怕死循环
else
r = mid;
}
dijkstra(l);
if (dis[n] > b)
printf("AFK\n");
else
printf("%lld\n", l);
return 0;
}
by 44_FeiDing @ 2023-08-25 07:32:49
@YangMieMie_ 你那个注释我看的好熟悉啊,你怕不是ctj的?
by 44_FeiDing @ 2023-08-25 07:33:33
@YangMieMie_ 那片题解有一处小错误,建议你换一篇抄。
by 44_FeiDing @ 2023-08-25 07:34:27
@YangMieMie_ 到了终点血量为〇也算成功,所以要改二分的判断条件。
by 44_FeiDing @ 2023-08-25 07:35:01
大佬顺便帮我调调你下面那篇帖子的代码呗。
by huoguo_fy @ 2023-09-02 15:11:00
@dltdltdlt 不好意思我才看到 还有需要吗,我不一定再什么时间看到。。。。
by 44_FeiDing @ 2023-09-02 16:43:43
@YangMieMie_ 我已经A了,谢谢你。