/ Randle /

记录详情

Runtime Error

/in/foo.cc: In function 'int main()':
/in/foo.cc:104:8: warning: unused variable 'x' [-Wunused-variable]
  int i,x,y;
        ^
/in/foo.cc:104:10: warning: unused variable 'y' [-Wunused-variable]
  int i,x,y;
          ^
# 状态 耗时 内存占用
#1 Accepted 18ms 26.375 MiB
#2 Accepted 23ms 26.25 MiB
#3 Accepted 23ms 26.266 MiB
#4 Accepted 27ms 24.332 MiB
#5 Accepted 25ms 26.25 MiB
#6 Accepted 22ms 26.359 MiB
#7 Accepted 16ms 26.352 MiB
#8 Accepted 24ms 26.25 MiB
#9 Accepted 11ms 24.469 MiB
#10 Accepted 17ms 26.375 MiB
#11 Accepted 38ms 30.875 MiB
#12 Accepted 49ms 33.852 MiB
#13 Accepted 20ms 27.0 MiB
#14 Runtime Error 283ms 37.812 MiB
#15 Accepted 284ms 40.5 MiB
#16 Accepted 284ms 40.434 MiB
#17 Accepted 255ms 42.25 MiB
#18 Accepted 439ms 42.262 MiB
#19 Accepted 423ms 41.023 MiB
#20 Accepted 424ms 37.266 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];
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;
		while(st[top]!=u)
		{
			color[st[top]]=scc;
			f[scc]++;
			vis[st[top--]]=0;
		}
		top--;
	}
}
int bfs()
{
	queue <int> q;
	int u,v;
	memset(d,0,sizeof(d));
	memset(vis,0,sizeof(vis));
	for(int i=1;i<=n;i++)
		if(!in[i])
		{
			q.push(i);
			d[i]=f[i];
		}
	while(!q.empty())
	{
		u=q.front();
		q.pop();
		for(int i=point[u];i;i=e[i].nex)
		{
			v=e[i].to;
			d[v]=max(d[v],d[u]+f[v]);
			in[v]--;
			if(!in[v])
			{
				vis[v]=1;
				q.push(v);
			}
		}
	}
	int ans=0;
	for(int i=1;i<=scc;i++)
		ans=max(ans,d[i]);
	return ans;
}
int main()
{
	//freopen("bomb20.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]]++;
		}
	cout<<bfs();	
}

信息

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