我知道不该怀疑一个两千人通过的题目。。。

P1462 通往奥格瑞玛的道路

Taduro @ 2018-06-29 14:28:55

但第八个点我下了数据输出是对的,可评测机提示我输出的是AFK。 我的代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define re register
using namespace std;
struct node{
    int next,to,z;
}w[100001];
ll f[10001],b,g[10001];
ll n,m,heap[10001],head,tail,team[10001];
ll o[10001],s[10001],z,x,y,l,r,mid,flag;
inline ll read(){
    int x=0,p=1; char ch=getchar();
    while (ch<'0'||ch>'9') {if (ch == '-') p=-1; ch=getchar();}
    while (ch>='0'&&ch<='9') {x=(x<<1)+(x<<3)+ch-'0'; ch=getchar();}
    return x*p;
}
bool spfa(ll c){
    if (g[1]>c||g[n]>c) return false;
    memset(o,0,sizeof(o));
    memset(s,30,sizeof(s));
    head=0; tail=1; team[head]=1;
    s[1]=0; o[1]=1;
    while (head<tail){
        int k=team[head];
        for (re ll i=heap[k]; i; i=w[i].next){
            if (s[w[i].to]>s[k]+w[i].z){
                s[w[i].to]=s[k]+w[i].z;
                if (!o[w[i].to]&&g[w[i].to]<=c&&s[w[i].to]<b){
                    o[w[i].to]=1;
                    team[tail]=w[i].to; tail++;
                }
            }
        }
        if (s[n]<b) return true;
        head++; o[k]=0;
    }
    return s[n]<b;
}
int main(){
    n=read(); m=read(); b=read();
    for (re ll i=1; i<=n; i++){
        f[i]=read(); g[i]=f[i];
    }
    for (re ll i=1; i<=m; i++){
        x=read(); y=read(); z=read();
        w[i].to=y; w[i].next=heap[x];
        w[i].z=z; heap[x]=i;
        w[i+m].to=x; w[i+m].next=heap[y];
        w[i+m].z=z; heap[y]=i+m;
    }
    sort(f+1,f+n+1);
    l=1; r=n;
    while (l<=r){
        mid=(l+r)/2;
        if (spfa(f[mid])){
            r=mid-1;
            flag=1;
        }
        else l=mid+1;
    }
    if (flag) printf("%lld",f[l]);
    else printf("AFK");
    return 0;
} 

输出应该是747332764


by Taduro @ 2018-06-29 14:29:16

求助


by かなで @ 2018-06-29 14:33:26

@多弗桃 emmm....Rk1要没


by Taduro @ 2018-06-29 14:36:05

好奇怪,把O2关了就没了


by Taduro @ 2018-06-29 14:36:44

好吧问题解决了,我把O2关上就A了


by Dispwnl @ 2018-06-29 14:58:06

(听说代码不规范有时候开O2会出错


by qqvq @ 2018-06-29 15:03:20

我无脑在每个数组后面加个0 不开O2就正常了


by かなで @ 2018-06-29 15:04:20

emm..Rk1果然没了


by qqvq @ 2018-06-29 15:04:50

@多弗桃


by かなで @ 2018-06-29 15:19:58

暴力夺回Rk1.jpg(huaji)


by Camorgx @ 2018-08-18 11:48:12

问一下诸位大佬O2能卡AC是不是因为它会把自己不规范的代码优化掉?


|