theHermit @ 2020-09-29 20:58:40
#include<bits/stdc++.h>
#define For(i,m,n) for(register int i=m;i<n;i++)
#define rFor(i,m,n) for(register int i=m;i>n;i--)
#define r(a) read(a)
#define rr(a,b) read(a),read(b)
#define rrr(a,b,c) read(a),read(b),read(c)
using namespace std;
typedef long long ll;
typedef unsigned long long Ull;
template <class T>
inline void read(T &x)
{
x=0;
T f=1;
char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
x=x*f;
}
const int MaxN = 50010, MaxM = 100100;
const int INF=1e9;
struct edge{
int next;
int to;
ll dis;
}e[MaxM];
int head[MaxN];
ll res[MaxN];
int tot=0;
bool vis[MaxM];
int n,m,s;
ll b;
ll fi[MaxN];
ll start,ed;
void add_edge(int from,int to,ll dis)
{
tot++;
e[tot].next=head[from];
e[tot].to=to;
e[tot].dis=dis;
head[from]=tot;
}
priority_queue<int,vector<int>,greater<int> > Q;
bool dijkstra(ll mid)
{
if(mid<start) return true;
For(i,1,n+1) res[i]=INF;
memset(vis,0,sizeof(vis));
res[s]=0;
Q.push(s);//保证从开始结点出发不断更新
while(Q.size()){
int x=Q.top();
Q.pop();
if(vis[x]) continue;
vis[x]=1;
for(int i=head[x];i;i=e[i].next){
int v=e[i].to;
if(fi[v]>mid) continue;
if(res[v]>res[x]+e[i].dis)
res[v]=res[x]+e[i].dis;
if(!vis[v]) Q.push(v);//保证了从起始节点往下走
}
}
return res[n]>=b;
}
int main()
{
rrr(n,m,b);
For(i,1,n+1) r(fi[i]);
start=fi[1];
s=1;
sort(fi+1,fi+1+n);
For(i,1,m+1){
ll u,v,d;
rrr(u,v,d);
add_edge(u,v,d);
add_edge(v,u,d);
}
if(dijkstra(fi[n])){
cout<<"AFK";
return 0;
}
ll lo,hi;
lo=1,hi=n+1;
while(lo<hi){
ll mid=(lo+hi)/2;
if(dijkstra(fi[mid])){
lo=mid+1;
}
else{
hi=mid;
}
}
cout<<fi[lo];
return 0;
}
by theHermit @ 2020-09-29 21:12:06
救救孩子呜呜呜呜呜
by theHermit @ 2020-09-29 22:04:38
自己搞定了。。。
首先是dijkstra弄错了。。。
Q.push没有按照当前贪心最短的原则。。
其次是用了排序以后的fi,这样原本的点序与排序后的fi序是不一致的...
我真菜QAQ