初学OI萌新求救

P1462 通往奥格瑞玛的道路

Sai0511 @ 2018-11-08 16:10:23

实在找不出哪里错了qaq,各位大佬救救我啊qaq

// luogu-judger-enable-o2
#include<bits/stdc++.h>
#define il inline
#define gc getchar
#define int long long
const int MAXN=1e4+10;
const int MAXM=5e5+10;
const int INF=1000000001;
using namespace std;
int n,m,i,j,k,HP,L,R,cnt,Ans;
int head[MAXN],dis[MAXN],f[MAXN];bool vis[MAXN];
struct Edge{
    int to,val,Next;
}G[MAXM];
struct io{
    il int read(){
        int x=0;char c;
        for(c=gc();!isdigit(c);c=gc()) ;
        for(;isdigit(c);c=gc()) x=(x<<1)+(x<<3)+(c^48);
        return x;
    }   
}Fio;
#define read Fio.read
il void spfa(){
    int i;
    queue<int>q;while(!q.empty()) q.pop();q.push(1);
    while(!q.empty()){
        int u=q.front(); q.pop();vis[u]=0;
        for(i=head[u];~i;i=G[i].Next){
            int to=G[i].to; int val=G[i].val;
            if(dis[u]+val<dis[to]){
                dis[to]=dis[u]+val;
                if(!vis[to]){
                    vis[to]=1;
                    q.push(to);
                }
            }
        }
    }
    return;
}
il bool Check(int HP){
    int i;
    memset(vis,0,sizeof(vis));
    for(i=1;i<=n;i++) dis[i]=INF; dis[1]=0; vis[1]=1;
    spfa();
    return dis[n]<HP;
}
il void addEdge(int u,int v,int val){
    G[++cnt].to=v;G[cnt].val=val;G[cnt].Next=head[u];
    head[u]=cnt;return;
}
signed main(){
    n=read();m=read();HP=read();        
    for(i=1;i<=n;i++) f[i]=read(),R=max(R,f[i]);L=max(f[1],f[n]);
    memset(head,-1,sizeof(head));
    for(i=1;i<=m;i++){
        int u=read(),v=read(),d=read();
        addEdge(u,v,d);addEdge(v,u,d);
    }
    if(!Check(INF)){printf("AFK");return 0;}
    while(L<=R){
        int mid=L+R>>1;
        if(Check(mid)) Ans=mid,R=mid-1;
        else L=mid+1;
    }printf("%lld",1LL*Ans);
    return 0;       
}

by hyfhaha @ 2018-11-08 16:13:15

@Sai_0511 多少分啊


by Sai0511 @ 2018-11-08 16:14:12

@hyfhaha 63


by hyfhaha @ 2018-11-08 16:17:35

@Sai_0511 没排序怎么二分啊?


by hyfhaha @ 2018-11-08 16:18:01

@Sai_0511 要保证有序才能二分啊


by Sai0511 @ 2018-11-08 16:20:09

@hyfhaha ...这二分的是血量啊...为什么要排序啊。。。


by Sai0511 @ 2018-11-08 16:21:07

@hyfhaha 更何况二分血量也无法排序啊。。。


by hyfhaha @ 2018-11-08 16:22:46

@Sai_0511 好吧我是直接二分最多的一次收取的费用的最小值是多少


by PPXppx @ 2018-11-08 16:23:13

最后求费用,为什么不二分费用???


by hyfhaha @ 2018-11-08 16:26:43

@Sai_0511 不明白怎么二分血量


by Sai0511 @ 2018-11-08 16:33:27

@hyfhaha 口误,,其实是二分费用。。不用在意


| 下一页