QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#474036#906. 强连通分量wangzhifang#WA 4ms16564kbC++141.1kb2024-07-12 15:42:102024-07-12 15:42:10

Judging History

你现在查看的是最新测评结果

  • [2024-07-12 15:42:10]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:16564kb
  • [2024-07-12 15:42:10]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
constexpr int inf_int=numeric_limits<int>::max();
constexpr int max_n=500000;
vector<int>g[max_n+1];
int low[max_n+1];
int stk[max_n+1],dfncnt,stkcnt;
vector<vector<int> >comps;
int dfsa(const int u){
	const int dfu=low[u]=++dfncnt;
	stk[++stkcnt]=u;
	int lwu=dfu;
	for(const int&v:g[u]){
		if(low[v]){
			if(low[v]<lwu)
				lwu=low[v];
			continue;
		}
		const int lwv=dfsa(v);
		if(lwv<lwu)
			lwu=lwv;
	}
	if(dfu==lwu){
		vector<int>vec;
		for(int v; (v=stk[stkcnt])!=u; --stkcnt)
			vec.emplace_back(v),low[v]=inf_int;
		vec.emplace_back(u),low[u]=inf_int,--stkcnt;
		comps.emplace_back(vec);
	}
	return low[u]=lwu;
}
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1,u,v; i<=m; ++i){
		scanf("%d%d",&u,&v);
		g[u].emplace_back(v);
	}
	for(int i=0; i<n; ++i)
		if(!low[i])
			dfsa(i);
	printf("%zd\n",comps.size());
	for(decltype(comps)::const_reverse_iterator it=comps.crbegin(),ed=comps.crend(); it!=ed; ++it){
		printf("%zd",it->size());
		for(const int&x:*it)
			printf(" %d",x);
		putchar('\n');
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 16564kb

input:

6 7
1 4
5 2
3 0
5 5
4 1
0 3
4 2

output:

3
2 4 1
1 2
2 3 0

result:

wrong answer # of scc is differ - expected: '4', found: '3'