/ Randle /

记录详情

Runtime Error


  
# 状态 耗时 内存占用
#1 Accepted 141ms 31.977 MiB
#2 Accepted 144ms 32.5 MiB
#3 Accepted 1479ms 30.742 MiB
#4 Accepted 201ms 31.5 MiB
#5 Accepted 148ms 32.125 MiB
#6 Accepted 153ms 32.625 MiB
#7 Accepted 144ms 32.5 MiB
#8 Time Exceeded ≥3007ms ≥32.219 MiB
#9 Accepted 16ms 32.348 MiB
#10 Accepted 16ms 31.75 MiB
#11 Accepted 26ms 35.875 MiB
#12 Accepted 39ms 35.969 MiB
#13 Accepted 19ms 35.34 MiB
#14 Runtime Error 248ms 38.727 MiB
#15 Time Exceeded ≥3004ms ≥39.367 MiB
#16 Accepted 212ms 41.121 MiB
#17 Accepted 200ms 39.625 MiB
#18 Time Exceeded ≥3006ms ≥37.59 MiB
#19 Time Exceeded ≥3004ms ≥37.625 MiB
#20 Time Exceeded ≥3001ms ≥37.605 MiB

代码

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
const int N=1000010;
int dfn[N],k=0,low[N],n,m,head[N],color[N],color_time,sta[N],top=0,tim=0,f[N],ans=0,rd[N],x[N],y[N];
bool vis[N];
struct node
{
    int to,nxt,from;
}edge[N];
void add(int u,int v)
{
    edge[++k].to=v;
    edge[k].from=u;
    edge[k].nxt=head[u];
    head[u]=k;
}
int read()
{
	int x=0;
	int f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
void tarjan(int s)//缩点
{
    dfn[s]=low[s]=++tim;
    sta[++top]=s;
    vis[s]=true;
    for(int i=head[s],v=edge[i].to;i;i=edge[i].nxt,v=edge[i].to)
    {
        if(!dfn[v])tarjan(v),low[s]=min(low[s],low[v]);
        else if(vis[v])low[s]=min(low[s],dfn[v]);
    }
    if(low[s]==dfn[s])
    {
        ++color_time;
        vis[s]=false;
        while(sta[top+1]!=s)
        {
            color[sta[top]]=color_time;//染色
            f[color_time]++;//求染色后点集权值和
            
            vis[sta[top]]=false;
            top--;
        }
    }
}
int dfs(int x)
{
	int ans1=f[x];
	int ans2=0;
	for(int i=head[x];i;i=edge[i].nxt)
	{
		int v=edge[i].to;
		ans2=max(ans2,dfs(v));
		
	}
	return ans1+ans2;
	
}

int main()
{

    scanf("%d%d",&n,&m);

    for(int i=1;i<=m;i++)
    {
        int u,v;
        u=read(),v=read();x[i]=u,y[i]=v;
        add(u,v);
    }
    for(int i=1;i<=n;i++)if(!dfn[i])tarjan(i);
    memset(head,0,sizeof(head));
    memset(edge,0,sizeof(edge));
    k=0;
    for(int i=1;i<=m;i++)
    {
        if(color[x[i]]!=color[y[i]])
        {
        	
            add(color[x[i]],color[y[i]]);
			rd[color[y[i]]]++;
        }
    
    }
    for(int i=1;i<=color_time;i++)
    {
    	if(!rd[i])
    	{
    		ans=max(ans,dfs(i));
		}

	}
    

    cout<<ans<<endl;
}

信息

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