/ Randle /

记录详情

Runtime Error


  
# 状态 耗时 内存占用
#1 Time Exceeded ≥3013ms ≥2.371 MiB
#2 Time Exceeded ≥3013ms ≥4.363 MiB
#3 Time Exceeded ≥3013ms ≥4.375 MiB
#4 Time Exceeded ≥3007ms ≥4.25 MiB
#5 Time Exceeded ≥3012ms ≥2.371 MiB
#6 Time Exceeded ≥3014ms ≥2.363 MiB
#7 Time Exceeded ≥3015ms ≥4.25 MiB
#8 Time Exceeded ≥3012ms ≥4.25 MiB
#9 Time Exceeded ≥3004ms ≥4.25 MiB
#10 Time Exceeded ≥3002ms ≥2.367 MiB
#11 Time Exceeded ≥3091ms ≥2.844 MiB
#12 Time Exceeded ≥3085ms ≥4.375 MiB
#13 Time Exceeded ≥3003ms ≥4.375 MiB
#14 Wrong Answer 29ms 5.105 MiB
#15 Runtime Error 123ms 4.727 MiB
#16 Time Exceeded ≥3044ms ≥5.641 MiB
#17 Runtime Error 39ms 4.75 MiB
#18 Time Exceeded ≥3005ms ≥8.496 MiB
#19 Time Exceeded ≥3008ms ≥8.5 MiB
#20 Time Exceeded ≥3001ms ≥8.848 MiB

代码

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
const int maxn = 1e5 + 1e4, maxm = 1e5 + 1e4;
int Index,pd[maxn],DFN[maxn],LOW[maxn];
int tot,color[maxn],sum[maxn],f[maxn];
int edge,fir[maxn],Next[maxm],to[maxm];
int sta[maxn],top; //手写栈 
int n,m,val[maxn],x[maxm],y[maxm],ans;
int read(){
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-48; ch=getchar();}
    return f*x;    
}
void add(int x,int y){
    to[++edge]=y; Next[edge]=fir[x]; fir[x]=edge;
}
void tarjan(int x){  
    sta[++top]=x;
    pd[x]=1;
    DFN[x]=LOW[x]= ++Index;
    for(int i=fir[x];i;i=Next[i]){
        int v=to[i];
        if(!DFN[v]){
            tarjan(v);
            LOW[x]=min(LOW[x],LOW[v]);
        }
        else if(pd[v]){
            LOW[x]=min(LOW[x],DFN[v]);
        }
    }
    if(DFN[x]==LOW[x]){
        tot++;
        while(sta[top+1]!=x){
            color[sta[top]]=tot;
            sum[tot]+=val[sta[top]];
            pd[sta[top--]]=0;
        }
    }
}
void search(int x){   //在DAG上记忆化搜索
    if(f[x]) return ;
    f[x]=sum[x];
    int maxsum = 0;
    for(int i=fir[x];i;i=Next[i]){
        if(!f[to[i]]) search(to[i]);
        maxsum=max(maxsum,f[to[i]]);
    }
    f[x]+=maxsum;
}
int main(){
    n=read(); m=read();
    for(int i=1;i<=n;i++) val[i]=read();
    for(int i=1;i<=m;i++){
        x[i]=read();                                // 这里用数组保存好原边,便于后续重新建图;
        y[i]=read();
        add(x[i],y[i]);
    }
    for(int i=1;i<=n;i++) if(!DFN[i]) tarjan(i);
    memset(fir,0,sizeof(fir));                 //清空原图
    memset(Next,0,sizeof(Next));
    memset(to,0,sizeof(to));
    edge=0;
    for(int i=1;i<=m;i++){       //重新建图(枚举每一条原边,若不在同一强连通分量里,则连一条边(方向同原边))
        if(color[x[i]]!=color[y[i]])
            add(color[x[i]],color[y[i]]);
    }
    for(int i=1;i<=tot;i++){  
        if(!f[i]){
            search(i);
            ans=max(ans,f[i]);
        }
    }
    printf("%d",ans);
    return 0;
}

信息

递交者
类型
递交
题目
BOMB炸弹(CQ直辖市noip模拟赛联考) T1
题目数据
下载
语言
C++
递交时间
2017-11-04 19:33:15
评测时间
2017-11-04 19:33:15
评测机
分数
0
总耗时
51543ms
峰值内存
8.848 MiB