BrandonSoong @ 2019-05-11 22:44:31
=============我叫分割线=============
#include<bits/stdc++.h>
#define maxn 550000
#define topleaf q.top().second
#define pii pair<int,int>
#define push(a) q.push(make_pair(leaf[a].dis,a))
#define int long long
using namespace std;
priority_queue <pii,vector<pii >,greater<pii > > q;
int n,m,cal,V,maxm;
struct lines{
int to,kill,nex;
}line[maxn<<1|1];
struct leaves{
int head,dis,cost;
bool used;
}leaf[maxn];
inline int qr()
{
int sum=0;
char j=0;
bool flag=0;
while(!isdigit(j))
{
flag|=j=='-';
j=getchar();
}
while(isdigit(j))
{
sum=(sum<<3)+(sum<<1)+(j^48);
j=getchar();
}
return flag? -sum:sum;
}
inline void readin()
{
n=qr();
m=qr();
V=qr();
int a,b,c;
for(int i=1;i<=n;i++)
leaf[i].cost=qr(),maxm=max(maxm,leaf[i].cost);
for(int i=1;i<=m;i++)
{
a=qr();
b=qr();
c=qr();
cal++;
line[cal].kill=c;
line[cal].nex=leaf[a].head;
line[cal].to=b;
leaf[a].head=cal;
cal++;
line[cal].kill=c;
line[cal].nex=a;
line[cal].nex=leaf[b].head;///////////
leaf[b].head=cal;
}
return;
}
inline bool Dijkstra(int k)
{
if(leaf[1].cost>k||leaf[n].cost>k)return 0;
for(int i=1;i<=n;i++)
leaf[i].dis=0x7777777777,leaf[i].used=0;
leaf[1].dis=0;
push(1);
for(int i=1;i<=n;i++)
if(leaf[i].cost>k)leaf[i].used=1;
while(!q.empty())
{
int u=topleaf;
q.pop();
if(leaf[u].used)continue;
leaf[u].used=1;
for(int i=leaf[u].head;i;i=line[i].nex)
{
int y=line[i].to;
int w=line[i].kill;
if(leaf[y].dis>leaf[u].dis+w)
{
leaf[y].dis=leaf[u].dis+w;
push(y);
}
}
}
if(leaf[n].dis<=V)return 1;
return 0;
}
inline void solve()
{
int l=0;
int r=1000000000;
int mid;
int ans=0;
if(!Dijkstra(1100000000))
{
printf("AFK");
return;
}
while(l<=r)
{
mid=(l+r)>>1;
if(Dijkstra(mid))
{
ans=mid;
r=mid-1;
}
else
l=mid+1;
}
printf("%lld",ans);
return;
}
signed main()
{
readin();
solve();
return 0;
}
by first_fan @ 2019-05-11 23:41:39
Orz BS