caramel_qwq @ 2022-07-06 16:02:59
存图用的邻接点列表,不是前向星
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
const int MAXN=10008;
typedef pair<int,int> pi;
priority_queue< pi,vector<pi>,greater<pi> > q;
int n,m,b;
int f[MAXN],dis[MAXN];
struct node{
int v,w;
};
vector<node> a[MAXN];
bool vis[MAXN];
int l=INT_MAX,r=INT_MIN,mid;
bool dijkstra(int st){
memset(vis,0,sizeof(vis));
memset(dis,INF,sizeof(dis));
dis[1]=st;
q.push({make_pair(dis[1],1)});
while(!q.empty()){
int x=q.top().second;
q.pop();
if(vis[x]) continue;
vis[x]=true;
for(int i=0;i<a[x].size();i++){
int y=a[x][i].v,z=a[x][i].w;
dis[y]=min(dis[y],dis[x]+z);
q.push(make_pair(dis[y],y));
}
}
return dis[n]<b;
}
int main(){
scanf("%d%d%d",&n,&m,&b);
for(int i=1;i<=n;i++){
scanf("%d",&f[i]);
l=min(l,f[i]);
r=max(r,f[i]);
}
int maxi=r;
for(int i=1;i<=n;i++){
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
a[u].push_back({v,w});
a[v].push_back({u,w});
}
while(l<=r){
mid=(l+r)/2;
if(dijkstra(mid)) r=mid-1;
else l=mid+1;
}
if(l==maxi+1)
printf("AFK\n");
else
printf("%d\n",l);
return 0;
}
by zenglu @ 2022-07-06 16:24:01
你有没有发现你根本没使用