ximz @ 2019-11-03 16:16:29
贴上代码
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <queue>
using namespace std;
struct note{
long long w,e,next;
}edge[10000010];
long long n,m,b,cnt,head[10001000],vis[10010000],dis[10001000],kx[1001000],kq[1001010],r,l=1,ans;//kx是扣钱
void add(int u,int v,long long w){
cnt++;
edge[cnt].w=w;
edge[cnt].e=v;
head[u]=cnt;
}
long long spfa(long long k){
queue <int>q;
memset(dis,0x3f,sizeof(dis));
for(long long i=1;i<=n;i++){
vis[i]=1;
}
q.push(1);
vis[1]=0;
dis[1]=0;
while(!q.empty()){
long long u=q.front();
q.pop();
vis[u]=1;
for(int i=head[u];i;i=edge[i].next){
long long v=edge[i].e;
if(kx[v]>k) continue;
if((dis[u]+edge[i].w)<dis[v]){
dis[v]=dis[u]+edge[i].w;
if(vis[v]){
q.push(v);
vis[v]=0;
}
}
}
}
if(dis[n]<b) return 1;
else return 0;
}
int main(){
cin >> n >> m >> b;
for(long long i=1;i<=n;i++){
cin >> kx[i];
kq[i]=kx[i];
}
sort(kq+1,kq+n+1);
for(long long i=1;i<=m;i++){
long long x,y,z;
cin >> x >> y >> z;
if (x==y) continue;
add(x,y,z);
add(y,x,z);
}
r=n;
while(l<=r){
long long mid=(l+r)/2;
if(spfa(kq[mid])){
ans=mid;
r=mid-1;
}
else l=mid+1;
}
if(ans!=0)
cout << kq[ans] << endl;
else{
cout << "AFK" << endl;
}
return 0;
}
现在就是自闭,非常自闭
by 利刃随人 @ 2019-11-07 14:41:52
27分血赚