平面向皮卡丘 @ 2019-11-10 21:07:11
#include <bits/stdc++.h>
using namespace std;
const int MAXN=10005;
const int MAXM=50005;
const int INF=1e9+5;
struct edge
{
int to,next,val;
}e[MAXM];
struct node
{
int num,dis;
bool operator < (const node& a) const {return dis<a.dis;}
bool operator > (const node& a) const {return dis>a.dis;}
};
int N,M,HP;
int dist[MAXN],head[MAXN];
int f[MAXN],fi[MAXN];
bool vis[MAXN];
int cnt;
int u,v,w;
void add(int x,int y,int v)
{
cnt++;
e[cnt].to=y;
e[cnt].next=head[x];
e[cnt].val=v;
head[x]=cnt;
}
bool check(int maxCost)
{
if(f[1]>maxCost) return false;
memset(dist,-1,sizeof(dist));
memset(vis,0,sizeof(vis));
priority_queue <node,vector<node>,greater<node> > q;
node st;
st.num=1;
st.dis=0;
dist[1]=0;
q.push(st);
while(!q.empty())
{
node cur=q.top();
q.pop();
if(vis[cur.num]) continue;
vis[cur.num]=1;
int now=head[cur.num];
while(now!=-1)
{
if((dist[e[now].to]==-1||dist[e[now].to]>dist[cur.num]+e[now].val)&&f[e[now].to]<=maxCost)
{
dist[e[now].to]=dist[cur.num]+e[now].val;
node temp;
temp.num=e[now].to;
temp.dis=dist[e[now].to];
q.push(temp);
}
now=e[now].next;
}
}
if(dist[N]>HP) return false;
else return true;
}
int main()
{
memset(head,-1,sizeof(head));
scanf("%d%d%d",&N,&M,&HP);
for(int i=1;i<=N;i++)
{
scanf("%d",&f[i]);
fi[i]=f[i];
}
sort(fi+1,fi+1+N);
for(int i=1;i<=M;i++)
{
scanf("%d%d%d",&u,&v,&w);
add(u,v,w);
add(v,u,w);
}
if(!check(INF))
{
printf("AFK");
return 0;
}
int left=1,right=N,ans=0;
while(left<=right)
{
int mid=(left+right)/2;
if(check(fi[mid])) right=mid-1,ans=fi[mid];
else left=mid+1;
}
printf("%d",ans);
return 0;
}
by ZhuMingYang @ 2019-11-10 21:08:40
明明是四色 举报了
by 行者_Walker @ 2019-11-10 21:21:18
好漂亮啊,难得见到这么丰富的色彩】
by 平面向皮卡丘 @ 2019-11-11 18:19:46
@行者_Walker Dalao帮忙靠一看啊
by 行者_Walker @ 2019-11-11 20:46:02
@平面向皮卡丘 额,我自己的都没调出来
by 平面向皮卡丘 @ 2020-07-28 18:05:53
@dshzsh 来看看吧
by 平面向皮卡丘 @ 2020-07-28 18:06:28
@阴阳八卦 来看看吧