Mistysun @ 2021-06-06 09:57:47
#include<bits/stdc++.h>
#define INF 1e9+7
using namespace std;
long long edgenum,vet[1000005],wei[1000005],nxt[1000005],head[1000005];
long long vis[1000005],dis[1000005],u,v,w,n,m,bb,l,r,mid,ans;
struct nod
{
long long va;
long long num;
}f[10000005];
struct node{
long long dis,id;
bool operator<(const node& a) const { return dis > a.dis;}
node(long long x,long long d) {dis =d, id=x;}
};
bool cmp(nod a,nod b)
{
return a.va<b.va;
}
void add(int u,int v,long long w)
{
edgenum++;
vet[edgenum]=v;
wei[edgenum]=w;
nxt[edgenum]=head[u];
head[u]=edgenum;
}
bool check(int x)
{
memset(vis,0,sizeof(vis));
for(int i=1;i<=n;i++)
if(f[i].va>f[x].va)vis[f[i].num]=1;
else vis[f[i].num]=0;
priority_queue<node> q;
while(!q.empty())q.pop();
for(int i=1;i<=n;i++)dis[i]=INF;
dis[1]=0;
q.push(node(1,0));
vis[1]=1;
while(!q.empty())
{
node u=q.top();
q.pop();
for(int i=head[u.id];i;i=nxt[i])
{
v=vet[i];
//printf("%d%d\n",v,vis[v]);
if(vis[v]==1)continue;
vis[v]=1;
//printf("%d %d %d\n",dis[v],dis[u.id],wei[i]);
if(dis[v]>dis[u.id]+wei[i])
{
dis[v]=dis[u.id]+wei[i];
//printf("%d %d\n",v,dis[v]);
q.push(node(v,dis[v]));
}
}
}
//printf("%d %d\n",x,dis[n]);
if(dis[n]<=bb)return true;
else return false;
}
bool bmp(nod a,nod b)
{
return a.va<b.va;
}
int main()
{
scanf("%d%d%d",&n,&m,&bb);
for(int i=1;i<=n;i++)
scanf("%d",&f[i].va),f[i].num=i;
sort(f+1,f+n+1,bmp);
for(int i=1;i<=m;i++)
{
scanf("%d%d%d",&u,&v,&w);
add(u,v,w);
add(v,u,w);
}
l=1;r=n;
ans=INF;
while(l<=r)
{
mid=(l+r)/2;
if(check(mid))ans=mid,r=mid-1;
else l=mid+1;
}
if(ans==INF)printf("AFK");
else printf("%lld",f[mid].va);
return 0;
}
by Qiaoqia @ 2021-06-06 10:48:20
@Mistysun 你这个……误导性极强,让我调来调去调不出,正感叹着我怎么如此基础不扎实,结果一翻看到你最后一句。
else printf("%lld",f[mid].va);
那么请问您记录下来的 ans
是干什么用的?
by Mistysun @ 2021-06-06 11:31:30
额?