xuke @ 2019-07-07 08:39:28
为啥这题我第八个测试点没过 其他都过了 算法也没看出有啥毛病
#include<iostream>
#include<queue>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
//ifstream cin(".in");
//ofstream cout(".out");
int n,m,b,MAXN=1000000100,s[100010],ans;
int inf=0x3f3f3f;
int f[100010];
struct node{
int to,h;
};
vector<node> q[100010];
int spfa(int value)
{
if(value<f[1]||value<f[n]) return 0;
int dis[100010],book[100010];
memset(book,0,sizeof(book));
memset(dis,inf,sizeof(dis));
dis[1]=0;
// book[1]=1;
queue<int> qu;
qu.push(1);
for(int i=1;i<=n;i++)
if(value<f[i]) book[i]=1;
while(!qu.empty())
{
int t=qu.front();
qu.pop();
if(book[t]) continue;
book[t]=1;
for(int i=0;i<q[t].size();i++)
{
if(dis[q[t][i].to]>dis[t]+q[t][i].h)
{
dis[q[t][i].to]=dis[t]+q[t][i].h;
qu.push(q[t][i].to);
}
}
}
if(dis[n]<b) return 1;
else return 0;
}
int main()
{
cin>>n>>m>>b;
int left=1,right=0;
for(int i=1;i<=n;i++)
{
cin>>f[i];
s[i]=f[i];
}
sort(s+1,s+n+1);
for(int i=1;i<=m;i++)
{
int x,y,z;
cin>>x>>y>>z;
if(x==y) continue;
node t;
t.to=y,t.h=z;
q[x].push_back(t);
t.to=x,t.h=z;
q[y].push_back(t);
}
if(!spfa(MAXN))
{
cout<<"AFK";
return 0;
}
left=1;
right=n;
ans=s[n];
while(left<=right)
{
int mid=(left+right)/2;
if(spfa(s[mid])) right=mid-1,ans=s[mid];
else left=mid+1;
}
cout<<ans;
return 0;
}