QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#44768#906. 强连通分量zmwang#WA 12ms50640kbC++141.2kb2022-08-21 15:48:132022-08-21 15:48:13

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-08-21 15:48:13]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:50640kb
  • [2022-08-21 15:48:13]
  • 提交

answer

#include<bits/stdc++.h>
#define int ll
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define qr read()
#define in(x) x=read()
#define nc getchar
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll read()
{
	char ch=' ';
	ll f=1,x=0;
	for(;!isdigit(ch);ch=nc())if(ch=='-')f*=-1;
	for(;isdigit(ch);ch=nc())x=x*10+ch-'0';
	return f*x;
}
int top=0,s[1000010],dfn[1000010],low[1000010],tim=0,ins[1000010],tot=0;
vector<int>ans[1000010],e[1000010];
void tarjan(int x)
{
	dfn[x]=low[x]=++tim;
	ins[x]=1;
	s[++top]=x;
	for(auto i:e[x])
	{
		if(!dfn[i])
		{
			tarjan(i);
			low[x]=min(low[x],low[i]);
		}
		else if(ins[i])low[x]=min(low[x],dfn[i]);
	}
	if(low[x]==dfn[x])
	{
		int now=0;
		tot++;
		do
		{
			now=s[top--];
			ins[now]=0;
			ans[tot].push_back(now);
		}while(now!=x);
	}
}
signed main()
{
	// freopen("a.in","r",stdin);
	// freopen(".out","w",stdout);
	int n=qr,m=qr;
	for(int i=1;i<=m;i++)
	{
		int x=qr,y=qr;
		e[x].push_back(y);
	}
	for(int i=0;i<n;i++)if(!dfn[i])tarjan(i);
	cout<<tot<<'\n';
	for(int i=1;i<=tot;i++)
	{
		cout<<ans[i].size()<<' ';
		for(auto j:ans[i])cout<<j<<' ';cout<<'\n';
	}
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 12ms
memory: 50640kb

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)