求助:WA测试点8,思路dijk+二分答案

P1462 通往奥格瑞玛的道路

Charles_Fan @ 2022-08-06 15:02:00

求助:WA测试点8,思路dijk+二分答案\ 下方是我认为有较大可能出错的代码片段:(完整代码见下)

const int NODE=1e4+10,EDGE=5e4+10,INF=1e9;
int n,m,health;
int price[NODE];//the price of going through node i
int head[NODE],wei[EDGE*2],to[EDGE*2],nxt[EDGE*2],edgcnt;
int dis[NODE];//shortest distance from 1 to i
namespace task2{
    int vis[NODE];
    bool able_to_connect;
    void dfs(int x,int limit){
        if(price[x]>limit){
            return;
        }
        if(vis[x]) return;
        vis[x]=1;
        if(x==n){
             able_to_connect=1;
             return;
        }
        for(int i=head[x];i;i=nxt[i]){
            int y=to[i];
            dfs(y,limit);
        }
    }
    void init(){
        able_to_connect=0;
        memset(vis,0,sizeof(vis));
    }
    void bi_section(){
        int l=0,r=1e9+114514,mid;
        while(r-l>1){
            mid=(l+r)/2;
            init();
            dfs(1,mid);
            if(able_to_connect){
                r=mid;
            }else l=mid;
            // cout<<l<<' '<<r<<' '<<mid<<endl;
        }
        init();
        dfs(1,r);
        if(able_to_connect) printf("%d\n",r);
        else printf("%d\n",l);
    }
}

评测结果见此处\ 完整代码见此处


|