_CMJ @ 2021-10-13 23:13:05
#include <bits/stdc++.h>
using namespace std;
const int KMaxN = 100005;
const int KMaxM = 500005;
const int INF = 0x3f3f3f3f;
struct node{
int next;
int to;
int val;
} e[2 * KMaxN];
int h[KMaxN], num;
int f[KMaxM];
int l, r;
bool vis[KMaxN];
int dis[KMaxN];
inline int read(){ //快读
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
inline void addedge(int u, int v, int w) {
e[++num].next = h[u];
e[num].to = v;
e[num].val = w;
h[u] = num;
return;
}
int n, m, b;
inline void spfa(int x) {
memset(dis, INF, sizeof(dis));
memset(vis, false, sizeof(vis));
queue<int> q;
q.push(1);
vis[1] = true;
dis[1] = 0;
while(q.size()) {
int u = q.front();
q.pop();
for (int i = h[u]; i; i = e[i].next){
int v = e[i].to;
if (dis[u] + e[i].val < dis[v] && f[v] <= x) {
dis[v] = dis[u] + e[i].val;
if (!vis[v]) {
vis[v] = true;
q.push(v);
}
}
}
}
return;
}
int main() {
// freopen("P1462_8.in", "r", stdin);
// freopen("hhh.out", "w", stdout);
n = read(), m = read(), b = read();
for (int i = 1; i <= n; i++) {
f[i] = read();
r = max(f[i], r);
}
l = max(f[1], f[n]);
int max_edge = 0;
for (int i = 1; i <= m; i++) {
int u, v, w;
u = read(), v = read(), w = read();
addedge(u, v, w), addedge(v, u, w);
max_edge = max(max_edge, w);
}
spfa(INF);
if (dis[n] > b) {
printf("AFK");
return 0;
}
while(l <= r) {
int mid = (l + r) / 2;
spfa(mid);
if (dis[n] > b) l = mid + 1;
else r = mid - 1;
}
printf("%d", l);
return 0;
}
by Chaser2 @ 2021-11-10 18:51:10
@Glmpise
你的spfa寄了,每次pop一个数后,要将这个数记录删除,即在q.pop();后加上vis[u]=false;
by _CMJ @ 2021-11-11 22:18:49
@Chaser2 谢谢大神,已关注
by Chaser2 @ 2021-11-11 23:54:22
@Glmpise
hh,我菜的很,刚学图论,然后来刷题巩固一下,e刚好这题我的方法和你的一样(已互关