/ Randle /

记录详情

Accepted


  
# 状态 耗时 内存占用
#1 Accepted 61ms 30.25 MiB
#2 Accepted 57ms 32.484 MiB
#3 Accepted 36ms 32.309 MiB
#4 Accepted 55ms 32.25 MiB
#5 Accepted 41ms 30.301 MiB
#6 Accepted 58ms 32.25 MiB
#7 Accepted 60ms 32.355 MiB
#8 Accepted 62ms 30.5 MiB
#9 Accepted 20ms 30.488 MiB
#10 Accepted 20ms 32.25 MiB
#11 Accepted 40ms 34.434 MiB
#12 Accepted 51ms 36.555 MiB
#13 Accepted 21ms 30.25 MiB
#14 Accepted 422ms 51.77 MiB
#15 Accepted 374ms 40.168 MiB
#16 Accepted 405ms 42.555 MiB
#17 Accepted 364ms 42.461 MiB
#18 Accepted 602ms 41.676 MiB
#19 Accepted 513ms 41.684 MiB
#20 Accepted 563ms 37.68 MiB

代码

#include <stdio.h>
#include <iostream>
#include <cstring>
const int maxn = 10e5+5;
using namespace std;
class stack {
		int a[maxn];
		int visit[maxn];
		int rare;
	public:
		void init() {
			memset(visit,0,sizeof(visit));
			rare= 0;
		}
	public:
		void push(int x) {
			visit[x] = 1;
			a[rare++] = x;
		}
	public:
		int pop() {
			int ret = a[--rare];
			visit[ret] = 0;
			return ret;
		}
	public:
		int isin(int x) {
			return visit[x];
		}
};
struct edge {
	int from,to;
} edges[maxn];
int in[maxn],head[maxn],nex[maxn],dis[maxn],q,diss[maxn];
inline void connect(int x,int y) {
	nex[++q] = head[x],dis[q] = y,head[x] = q;
}
stack s;
int colocc,dfn[maxn],low[maxn],scc,f[maxn],val[maxn];
void tarjan(int a) {
	dfn[a] = low[a] = ++colocc;
	s.push(a);
	for(int i = head[a]; i; i=nex[i]) {
		if(!dfn[dis[i]]) {
			tarjan(dis[i]);
			low[a] = min(low[a],low[dis[i]]);
		} else if(s.isin(dis[i])) low[a] = min(low[a],dfn[dis[i]]);
	}
	if(dfn[a]==low[a]) {
		scc++;
		do {
			a = s.pop();
			f[a] = scc;
			val[scc] ++;
		} while(dfn[a]!=low[a]);
	}
}
int que[maxn],rare,hh;
int main() {
	s.init();
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i = 1; i<=m; i++) {
		int x,y;
		scanf("%d%d",&x,&y);	
		connect(y,x);
		edges[i].from = y,edges[i].to  = x;
	}
	int ans = 0;
	for(int i = 1; i<=n; i++) if(!dfn[i]) tarjan(i);
	memset(head,0,sizeof(head));
	memset(nex,0,sizeof(nex));
	memset(dis,0,sizeof(dis));
	q = 0;
	for(int i = 1; i<=m; i++)
		if(f[edges[i].from]!=f[edges[i].to]) {
			connect(f[edges[i].from],f[edges[i].to]);
			in[f[edges[i].to]]++;
		}
	for(int i = 1;i<=scc;i++){
		if(in[i]==0){
			diss[i] = val[i];
			ans = max(ans,val[i]);
			que[rare++] = i;
		}
	}
	
	while(hh<rare){
		int a = que[hh++];
		for(int i = head[a];i;i = nex[i]){
			int to = dis[i];
			diss[to] = max(diss[to],diss[a]+val[to]);
			ans = max(ans,diss[to]);
			in[to]--;
			if(in[to]==0){
				que[rare++] = to;
			}
		}
	}
	cout<<ans;
	return 0;
}

信息

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