xhyf77 @ 2019-07-21 17:17:52
re+wa 不知道为啥欸 求聚聚帮帮忙
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000010
int val[100010],dis[100010],n,m,k,MAX,heap_size,vis[100010];
vector<int> Q[100010];
vector<int> edge[100010];
struct node{
int num,d;
}heap[100010];
void add(int num,int d){
node a;a.num=num;a.d=d;
heap[++heap_size]=a;
int now=heap_size;
while(now>1){
int next=now>>1;
if(heap[now].d>=heap[next].d) break;
swap(heap[now],heap[next]);
now=next;
}
}
void insert(){
node res=heap[heap_size];
heap[1]=res;
heap_size--;
int now=1;
while(now*2<=heap_size){
int next=now*2;
if(next<heap_size&&heap[next+1].d<heap[next].d) next++;
if(heap[now].d<=heap[next].d) break;
swap(heap[now],heap[next]);
now=next;
}
}
bool check(int mid){
if(mid<val[1]||mid<val[n]) return false;
dis[1]=0;
add(1,0);
while(heap_size){
int x=heap[1].num;insert();
if(vis[x]) continue;
vis[x]=1;
for(int i=0;i<Q[x].size();i++){
int y=Q[x][i];
int w=edge[x][i];
if(val[y]>mid) continue;
if(dis[y]>dis[x]+w){
dis[y]=dis[w]+w;
if(!vis[y]){
add(y,dis[y]);
}
}
}
}
if(dis[n]>k) return false;
else return true;
}
void clean(){
memset(vis,0,sizeof(vis));
memset(heap,0,sizeof(heap));
for(int i=1;i<=n;i++) dis[i]=INF;
heap_size=0;
}
int main(){
cin>>n>>m>>k;
for(int i=1;i<=n;i++){
cin>>val[i];
MAX=max(MAX,val[i]);
}
for(int i=1;i<=m;i++){
int x,y,z;
cin>>x>>y>>z;
Q[x].push_back(y);
Q[y].push_back(x);
edge[x].push_back(z);
edge[y].push_back(z);
}
int l=0,r=MAX;
if(check(r)==false){
cout<<"AFK";
return 0;
}
while(l<r){
clean();
int mid=(l+r)>>1;
if(check(mid)) r=mid;
else l=mid+1;
}
cout<<l;
}