/ Randle /

记录详情

Runtime Error

/in/foo.cc: In function 'int main()':
/in/foo.cc:105:8: warning: unused variable 'x' [-Wunused-variable]
  int i,x,y;
        ^
/in/foo.cc:105:10: warning: unused variable 'y' [-Wunused-variable]
  int i,x,y;
          ^
# 状态 耗时 内存占用
#1 Accepted 41ms 26.438 MiB
#2 Accepted 46ms 26.25 MiB
#3 Accepted 44ms 26.25 MiB
#4 Accepted 32ms 24.367 MiB
#5 Accepted 46ms 26.34 MiB
#6 Accepted 46ms 26.309 MiB
#7 Accepted 33ms 26.262 MiB
#8 Accepted 43ms 24.25 MiB
#9 Accepted 14ms 26.375 MiB
#10 Accepted 12ms 26.262 MiB
#11 Accepted 39ms 30.902 MiB
#12 Accepted 48ms 27.75 MiB
#13 Accepted 20ms 29.125 MiB
#14 Runtime Error 276ms 42.312 MiB
#15 Accepted 290ms 40.559 MiB
#16 Accepted 278ms 40.434 MiB
#17 Accepted 283ms 40.34 MiB
#18 Accepted 445ms 39.809 MiB
#19 Accepted 442ms 39.625 MiB
#20 Accepted 438ms 41.973 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;
		ans=max(ans,f[scc]);
		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:20:15
评测时间
2017-11-04 21:20:15
评测机
分数
95
总耗时
2925ms
峰值内存
42.312 MiB