/ Randle /

记录详情

Runtime Error

/in/foo.cc: In function 'int main()':
/in/foo.cc:103:8: warning: unused variable 'x' [-Wunused-variable]
  int i,x,y;
        ^
/in/foo.cc:103:10: warning: unused variable 'y' [-Wunused-variable]
  int i,x,y;
          ^
# 状态 耗时 内存占用
#1 Accepted 88ms 26.25 MiB
#2 Accepted 91ms 24.215 MiB
#3 Accepted 116ms 26.375 MiB
#4 Accepted 99ms 26.254 MiB
#5 Accepted 111ms 24.352 MiB
#6 Accepted 114ms 26.375 MiB
#7 Accepted 122ms 26.25 MiB
#8 Accepted 89ms 26.25 MiB
#9 Accepted 15ms 26.5 MiB
#10 Accepted 17ms 26.34 MiB
#11 Accepted 36ms 28.875 MiB
#12 Accepted 45ms 31.75 MiB
#13 Accepted 21ms 29.0 MiB
#14 Runtime Error 257ms 42.266 MiB
#15 Accepted 362ms 40.559 MiB
#16 Accepted 283ms 38.574 MiB
#17 Accepted 286ms 38.309 MiB
#18 Time Exceeded ≥3010ms ≥40.828 MiB
#19 Time Exceeded ≥3006ms ≥42.918 MiB
#20 Time Exceeded ≥3009ms ≥40.773 MiB

代码

#include <bits/stdc++.h>
using namespace std;
const int maxn=1000010;
inline int read()
{
	char ch=getchar();
	int x=0;
	while(!isdigit(ch))
		ch=getchar();
	while(isdigit(ch))
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x;
}

int n,m;
struct edge
{
	int to,nex;
}e[maxn<<1];
struct node
{
	int x,y;
}b[maxn];
int point[maxn],cnt=0;

inline void add(int x,int y)
{
	e[++cnt].to=y;
	e[cnt].nex=point[x];
	point[x]=cnt;
}

int st[maxn],top=0,vis[maxn],d[maxn];
int dfn[maxn],low[maxn],color[maxn],scc=0,id=0;
int f[maxn],ans,in[maxn];
void tarjan(int u)
{
	dfn[u]=low[u]=++id;
	st[++top]=u,vis[u]=1;
	for(int i=point[u];i;i=e[i].nex)
	{
		int v=e[i].to;
		if(!dfn[v])
		{
			tarjan(v);
			low[u]=min(low[u],low[v]);
		}
		else if(vis[v])
			low[u]=min(low[u],dfn[v]);
	}
	if(dfn[u]==low[u])
	{
		vis[u]=0;
		color[u]=++scc;
		f[scc]=1;
		ans=max(ans,f[scc]);
		while(st[top]!=u)
		{
			color[st[top]]=scc;
			f[scc]++;
			ans=max(ans,f[scc]);
			vis[st[top--]]=0;
		}
		top--;
	}
}
void spfa(int x)
{
	queue <int> q;
	int u,v;
	memset(d,0,sizeof(d));
	memset(vis,0,sizeof(vis));
	q.push(x),vis[x]=1,d[x]=f[x];
	while(!q.empty())
	{
		u=q.front();
		q.pop();
		vis[u]=0;
		for(int i=point[u];i;i=e[i].nex)
		{
			v=e[i].to;
			if(d[v]<d[u]+f[v])
			{
				d[v]=d[u]+f[v];
				if(!vis[v])
				{
					vis[v]=1;
					q.push(v);
				}
			}
		}
	}
	for(int i=1;i<=scc;i++)
		ans=max(ans,d[i]);
}
int main()
{
	//freopen("bomb4.in","r",stdin);
	//freopen("bomb.out","w",stdout);
	int i,x,y;
	n=read(),m=read();
	for(i=1;i<=m;i++)
	{
		b[i].x=read(),b[i].y=read();
		add(b[i].x,b[i].y);
	}
	for(i=1;i<=n;i++)
		if(!dfn[i])
			tarjan(i);
	memset(point,0,sizeof(point));
	cnt=0;
	for(i=1;i<=m;i++)
		if(color[b[i].x]!=color[b[i].y])
		{
			add(color[b[i].x],color[b[i].y]);
			in[color[b[i].y]]++;
		}
	for(i=1;i<=scc;i++)
		if(!in[i])
			spfa(i);
	cout<<ans;	
}

信息

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