p1462 求助qwq

P1462 通往奥格瑞玛的道路

顾z @ 2018-09-18 10:12:33

bfs80分 qwq, 最后两个点出问题 qwq

#include<bits/stdc++.h>
#define IL inline
#define int long long
#define RI register int
using namespace std;
IL void in(int &x)
{
    int f=1;x=0;char s=getchar();
    while(s>'9' or s<'0'){if(s=='-')f=-1;s=getchar();}
    while(s>='0' and s<='9'){x=x*10+s-'0';s=getchar();}
    x*=f;
}
int n,m,b,f[10008],head[10008],tot,mxx,ans=-1,mnn=2147483647;
bool vis[10008];
struct cod{int u,v,w;}edge[50000*2+1];
struct code{int now,Hp;};
IL void add(int x,int y,int z){edge[++tot].u=head[x];edge[tot].v=y;edge[tot].w=z;head[x]=tot;}
IL bool ok(int x)
{
    memset(vis,0,sizeof vis);
    queue<code>q;
    while(!q.empty())q.pop();
    q.push((code){1,b});
    vis[1]=true;
    while(!q.empty())
    {
        int u=q.front().now,Hp=q.front().Hp;
        q.pop();
        if(u==n)return true;
        for(RI i=head[u];i;i=edge[i].u)
        {
            if(vis[edge[i].v])continue;
            if(edge[i].w>=Hp)continue;
            if(f[edge[i].v]>x)continue;
            vis[edge[i].v]=true;
            q.push((code){edge[i].v,Hp-edge[i].w});
            if(edge[i].v==n)return true;
        }
    }
    return false;
}
signed main()
{
    in(n),in(m),in(b);
    for(RI i=1;i<=n;i++)in(f[i]),mxx=max(mxx,f[i]),mnn=min(mnn,f[i]);
    for(RI i=1,x,y,z;i<=m;i++)
    {
        in(x),in(y),in(z);
        if(x==y)continue;
        add(x,y,z),add(y,x,z);
    }
    int l=mnn,r=mxx;
    while(l<=r)
    {
        int mid=(l+r)>>1;
        if(ok(mid))r=mid-1,ans;
        else l=mid+1;
    }
    if(ans==-1) puts("AFK");
    else printf("%lld",ans);
}

by Mosklia @ 2018-09-18 10:13:51

@顾z 您的代码……毒瘤?


by 顾z @ 2018-09-18 10:15:26

@Sparky_14145 为什么这么说 QAQ


by EaEa @ 2018-09-18 10:45:10

我这才发现自己咕了好多题


by 顾z @ 2018-09-18 10:57:58

@c。 ?咋了


by EaEa @ 2018-09-18 11:11:12

@顾z 昨天的题都没做owo


by 顾z @ 2018-09-18 11:11:41

@c。 我欠了至少三天的了 woc


by EaEa @ 2018-09-18 11:12:54

@顾z emmmmm。强


|