/ Randle /

记录详情

Runtime Error


  
# 状态 耗时 内存占用
#1 Accepted 65ms 28.375 MiB
#2 Accepted 54ms 26.25 MiB
#3 Accepted 196ms 26.316 MiB
#4 Accepted 187ms 28.34 MiB
#5 Accepted 229ms 30.25 MiB
#6 Accepted 220ms 26.25 MiB
#7 Accepted 270ms 28.215 MiB
#8 Accepted 70ms 28.332 MiB
#9 Accepted 190ms 28.348 MiB
#10 Accepted 51ms 28.25 MiB
#11 Time Exceeded ≥3005ms ≥35.875 MiB
#12 Time Exceeded ≥3002ms ≥40.375 MiB
#13 Time Exceeded ≥3003ms ≥28.75 MiB
#14 Runtime Error 243ms 56.711 MiB
#15 Accepted 2014ms 58.625 MiB
#16 Accepted 476ms 57.316 MiB
#17 Accepted 2251ms 61.027 MiB
#18 Time Exceeded ≥3004ms ≥80.375 MiB
#19 Time Exceeded ≥3009ms ≥82.5 MiB
#20 Time Exceeded ≥3009ms ≥80.5 MiB

代码

#include<cstdio>
#include<iostream>
#include<cstring>
#include<stack>
#include<queue>
#define maxn 1010001
using namespace std;
typedef long long ll;
stack<ll>q;
queue<ll>s;
ll a[maxn],belong[maxn];
ll sum=0;
inline ll read()
{
    ll x=0;char c=getchar();
    while(c<'0'||c>'9') c=getchar();
    while(c>='0'&&c<='9')
    {
        x=x*10+c-'0';
        c=getchar();
    }
    return x;
}
struct Edge
{
    ll to,next,from;
}edge1[maxn*4],edge2[maxn*4];
ll head1[maxn],head2[maxn];
ll dis[maxn];ll dis1[maxn];
ll indegree[maxn];
ll dfn[maxn],low[maxn],dex=0;
bool vis[maxn],ins[maxn];
ll sum1,sum2;
ll ans=0;
inline void add_edge1(ll from,ll to)
{
    edge1[++sum1].next=head1[from];
    edge1[sum1].from=from;
    edge1[sum1].to=to;
    head1[from]=sum1;
}
inline void add_edge2(ll from,ll to)
{
    edge2[++sum2].next=head2[from];
    edge2[sum2].to=to;
    head2[from]=sum2;
}
inline void tarjan(ll u)
{
    vis[u]=1;
    ins[u]=1;
    q.push(u);
    dfn[u]=low[u]=++dex;
    for(ll i=head1[u];i;i=edge1[i].next)
    {
        ll v=edge1[i].to;
        if(!dfn[v])
        {
            tarjan(v);
            low[u]=min(low[u],low[v]);
        }
        if(ins[v])
        low[u]=min(low[u],dfn[v]);
    }
    if(dfn[u]==low[u])
    {
        sum++;
        ll t=q.top();
        while(t!=u)
        {
            belong[t]=sum;
            dis[sum]+=a[t];
            ins[t]=0;
            q.pop();
            t=q.top();
        }
        belong[t]=sum;
        dis[sum]+=a[t];
        ins[t]=0;
        q.pop();
    }
    return ;
}
inline void spfa(ll u)
{
    ans=max(ans,dis[u]);
    s.push(u);
    dis1[u]=dis[u];
    ins[u]=1;
    while(!s.empty())
    {
        ll t=s.front();
        s.pop();
        ins[t]=0;
        for(ll i=head2[t];i;i=edge2[i].next)
        {
            ll v=edge2[i].to;
            if(dis1[t]+dis[v]>dis1[v])
            {
                dis1[v]=dis1[t]+dis[v];
                ans=max(ans,dis1[v]);
                if(!ins[v])
                s.push(v); 
            }
        }
    }
}
int main()
{
    ll n,m;
    n=read();m=read();
    for(ll i=1;i<=n;i++)
    {
        a[i]=1;
    }
    ll from,to;
    for(ll i=1;i<=m;i++)
    {
        from=read();to=read();
        add_edge1(from,to);
    }
    for(ll i=1;i<=n;i++)
    {
        if(!vis[i]) tarjan(i);
    }    
    for(ll i=1;i<=sum1;i++)
    {
        from=edge1[i].from;to=edge1[i].to;
        if(belong[from]!=belong[to])
        {
            add_edge2(belong[from],belong[to]);
            indegree[belong[to]]++;
        }
    }
    for(ll i=1;i<=sum;i++)
    {
        memset(dis1,0,sizeof(dis1));
        if(indegree[i]==0)
        spfa(i);
    }
    printf("%lld",ans);
    return 0;
}

信息

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