Mozani @ 2019-11-12 13:36:27
#include<bits/stdc++.h>
using namespace std;
int n,m,t,l,r,b,c[10007],ver[100007],edge[100007],head[100007],nextt[100007];
bool flag[100007];
long long d[100007];
priority_queue <pair<int,int> > q;
bool dijkstra(int k)
{
if(k<c[1]||k<c[n])return 0;
memset(flag,0,sizeof(flag));
for(int i=1;i<=n;i++)
d[i]=0x7fffffff;
q.push(make_pair(0,1));
d[1]=0;
//ac代码
for(int i=1;i<=n;i++)
if(c[i]>k)flag[i]=1;
while(!q.empty())
{
int x=q.top().second;
q.pop();
if(flag[x])continue;
flag[x]=1;
for(int i=head[x];i;i=nextt[i])
{
int y=ver[i],z=edge[i];
if(d[y]>d[x]+z)
{
d[y]=d[x]+z;
q.push(make_pair(-d[y],y));
}
}
}
//ac代码结束
/*72分
while(!q.empty())
{
int x=q.top().second;
q.pop();
if(flag[x])continue;
flag[x]=1;
for(int i=head[x];i;i=nextt[i])
{
int y=ver[i],z=edge[i];
if(d[y]>d[x]+z&&c[i]<=k)
{
d[y]=d[x]+z;
q.push(make_pair(-d[y],y));
}
}
}
*/
if(d[n]>=b)return 0;
else return 1;
}
int main()
{
scanf("%d%d%d",&n,&m,&b);
for(int i=1;i<=n;i++)
{
scanf("%d",&c[i]);
r=max(r,c[i]);
}
l=max(c[1],c[n]);
for(int i=1;i<=m;i++)
{
int x,y,z;
cin>>x>>y>>z;
ver[++t]=y;
edge[t]=z;
nextt[t]=head[x];
head[x]=t;
ver[++t]=x;
edge[t]=z;
nextt[t]=head[y];
head[y]=t;
}
if(!dijkstra(r))
{
cout<<"AFK"<<endl;
return 0;
}
while(l<=r)
{
int mid=(l+r)/2;
if(dijkstra(mid))r=mid-1;
else l=mid+1;
}
printf("%d\n",l);
return 0;
}
by szzjz @ 2021-08-19 15:33:58
我也很困惑.....