初学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:37:38

@Sai_0511 那要排序啊


by Sai0511 @ 2018-11-08 16:38:45

过了


by hyfhaha @ 2018-11-08 16:38:51

@Sai_0511 神了,你没排序可以63,我没排序才27


上一页 |