xiangling @ 2018-10-28 16:15:53
RT。不知道哪里错了qwq
//code by rainman,luogu P1462
#include<cstdio>
#include<queue>
#define MAX(a,b) ((a)>(b)?(a):(b))
#define INF 0x7fffffff
using namespace std;
const int MAXN = 10000+10;
const int MAXM = 50000+10;
struct Edge{int v,w,next;}edge[MAXM<<1];
int tot,head[MAXN],n,m,b,l,r;
int f[MAXN],dis[MAXN];
bool inq[MAXN];
inline void addedge(int x,int y,int z)
{
edge[++tot].v=y;
edge[tot].w=z;
edge[tot].next=head[x];
head[x]=tot;
}
bool spfa(int cost)
{
if(f[1]>cost)return false;
for(int i=1;i<=n;i++)dis[i]=INF;
queue<int> qwq; dis[1]=0;
qwq.push(1); inq[1]=true;
while(!qwq.empty())
{
int x=qwq.front();
qwq.pop(); inq[x]=false;
for(int i=head[x];i;i=edge[i].next)
{
int y=edge[i].v,hp=edge[i].w;
if(dis[y]>dis[x]+hp&&f[y]<=cost)
{
dis[y]=dis[x]+hp;
if(!inq[y]){
qwq.push(y);
inq[y]=true;
}
}
}
}
if(dis[n]<b)return true;
return false;
}
int main()
{
scanf("%d%d%d",&n,&m,&b);
for(int i=1;i<=n;i++)scanf("%d",&f[i]);
for(int i=1;i<=n;i++)r=MAX(r,f[i]);
for(int i=1;i<=m;i++)
{
int x,y,z;scanf("%d%d%d",&x,&y,&z);
if(x==y)continue;
addedge(x,y,z); addedge(y,x,z);
}
int temp=r;
l=MAX(f[1],f[n]);
if(!spfa(1001001000)){puts("AFK");return 0;}
while(l<r)
{
int mid=(l+r)>>1;
if(spfa(mid))r=mid;
else l=mid+1;
}
if(r==temp&&(!spfa(r)))puts("AFK");
else printf("%d",r);
return 0;
}
by 引领天下 @ 2018-10-28 16:19:25
@rainman 性别未知。海星
by wxy_god @ 2018-10-28 16:26:05
@rainman 性别未知。海星
by 娄口肃行 @ 2018-10-28 16:26:39
spfa已经死了...
by 娄口肃行 @ 2018-10-28 16:27:29
AFK上面不是看过了嘛(性别未知一般是xjj)
by andyli @ 2018-10-28 16:28:43
@rainman 性别未知。海星
by 娄口肃行 @ 2018-10-28 16:30:13
结论:AFK判错了...(1,4,7)
恶意破坏队形
by zyxzrzxm @ 2018-10-28 16:32:32
@rainman 道理我都懂,可你为啥没有性别
by xiangling @ 2018-10-28 16:33:31
@娄口肃行 怎么错了啊?求大佬解释或发一下代码?
by 娄口肃行 @ 2018-10-28 17:35:01
@rainman 我写的dj+堆,你只要在二分前判一次spfa(r+1)即可,l应该是0或者f中的最小值吧...
by 娄口肃行 @ 2018-10-28 17:35:33
@rainman 啊不,这好像是对的...