QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#92682#906. 强连通分量zhangboju#WA 4ms29512kbC++141.1kb2023-03-30 20:51:142023-03-30 20:51:17

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-30 20:51:17]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:29512kb
  • [2023-03-30 20:51:14]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
template <typename T> inline void read(T &x)
{
	x=0;short f=1;char c=getchar();
	for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
	for(;c>='0'&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48);
	x*=f;return;
}
const int N=5e5+5;
int n,m;
vector<int>g[N];
int dfn[N],low[N],dfs_clock;
int stk[N],top;
bool in_stk[N];
int scc_cnt;
vector<int>ve[N];
void tarjan(int u)
{
	dfn[u]=low[u]=++dfs_clock;
	stk[++top]=u,in_stk[u]=1;
	for(int v:g[u])
	{
		if(!dfn[v])
		{
			tarjan(v);
			low[u]=min(low[u],low[v]);
		}
		else if(in_stk[v]) low[u]=min(low[u],dfn[v]);
	}
	if(dfn[u]==low[u])
	{
		++scc_cnt;
		int y;
		do{
			y=stk[top--];
			in_stk[y]=0;
			ve[scc_cnt].push_back(y);
		}while(y!=u);
	}
}
int main()
{
	read(n),read(m);
	for(int i=1;i<=m;++i)
	{
		int u,v;read(u),read(v);
		g[u].push_back(v);
	}
	for(int i=0;i<n;++i)
		if(!dfn[i]) tarjan(i);
	printf("%d\n",scc_cnt);
	for(int i=1;i<=scc_cnt;++i)
	{
		printf("%d ",ve[i].size());
		for(int x:ve[i]) printf("%d ",x);
		puts("");
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

4
2 3 0 
1 2 
2 4 1 
1 5 

result:

wrong answer 5 is later than 2, but there is an edge (5, 2)