QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#918649#906. 强连通分量paul2008#WA 0ms10068kbC++201.0kb2025-02-27 21:49:542025-02-27 21:50:02

Judging History

This is the latest submission verdict.

  • [2025-02-27 21:50:02]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 10068kb
  • [2025-02-27 21:49:54]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;

const int N=5e5+5;

int head[N], nex[N*2], to[N*2], indx=1;

void add(int x,int y)
{
	indx++;
	nex[indx]=head[x];
	to[indx]=y;
	head[x]=indx;
}

int dfsn[N], low[N], stk[N], top, cnt, SCC;
vector <int> vec[N];
bool instack[N];

void tarjan(int x)
{
	dfsn[x]=low[x]=++cnt;
	instack[x]=true, stk[++top]=x;
	for(int i=head[x];i;i=nex[i])
	{
		int y=to[i];
		if(!dfsn[y])
			tarjan(y), low[x]=min(low[x],low[y]);
		else if(instack[y])
			low[x]=min(low[x],dfsn[y]);
	}

	if(dfsn[x]==low[x])
	{
		SCC++;
		int y=0;
		do
		{
			y=stk[top--];
			instack[y]=false;
			vec[SCC].push_back(y);
		}
		while(x!=y);
	}
}

int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d %d",&x,&y);
		add(x,y);
	}
	
	for(int i=0;i<n;i++)
		if(!dfsn[i])
			tarjan(i);

	for(int i=SCC;i>=1;i--)
	{
		printf("%d ",vec[i].size());
		for(auto x:vec[i])
			printf("%d ",x);
		printf("\n");
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 10068kb

input:

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

output:

1 5 
2 4 1 
1 2 
2 3 0 

result:

wrong answer twice used vertex 1