QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#480229#906. 强连通分量Hanghang#RE 3ms13488kbC++141010b2024-07-16 10:50:382024-07-16 10:50:38

Judging History

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

  • [2024-07-16 10:50:38]
  • 评测
  • 测评结果:RE
  • 用时:3ms
  • 内存:13488kb
  • [2024-07-16 10:50:38]
  • 提交

answer

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

typedef long long ll;
#define pb push_back 
const int N=1e5+3;
int n,m,tim,tot,top,dfn[N],low[N],col[N],sta[N],kx[N],ky[N],in[N];
vector<int>ve[N],ans[N],now[N];
void Dfs(int x)
{
	low[x]=dfn[x]=++tim;sta[++top]=x;
	for(int y:ve[x])
	{
		if(dfn[y]){if(!col[y])low[x]=min(low[x],dfn[y]);continue;}
		Dfs(y);low[x]=min(low[x],low[y]);
	}
	if(dfn[x]==low[x])for(tot++;sta[top+1]!=x;top--)col[sta[top]]=tot;
}
int main()
{
	cin>>n>>m;
	for(int i=1,x,y;i<=m;i++)
		cin>>x>>y,ve[++x].push_back(++y),kx[i]=x,ky[i]=y;
	for(int i=1;i<=n;i++)if(!dfn[i])Dfs(i);
	for(int i=1;i<=n;i++)ans[col[i]].pb(i);
	for(int i=1,x,y;i<=m;i++)
	    if((x=col[kx[i]])!=(y=col[ky[i]]))now[x].pb(y),in[y]++; 
	cout<<tot<<endl;queue<int>q;
	for(int i=1;i<=tot;i++)if(!in[i])q.push(i);
	while(q.size())
	{
		int x=q.front();q.pop();
		cout<<ans[x].size()<<" ";
		for(int z:ans[x])cout<<z-1<<" ";
		cout<<endl;
		for(int y:now[x])if(!--in[y])q.push(y); 
	}
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 13488kb

input:

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

output:

4
2 0 3 
2 1 4 
1 5 
1 2 

result:

ok OK

Test #2:

score: -100
Runtime Error

input:

500000 500000
389812 410922
255712 339244
274009 248522
347288 199231
235313 301629
469588 84917
364188 449407
392348 436920
26220 198288
162188 468965
274222 92196
463222 408478
231663 467768
382681 38083
412497 160479
280851 268689
101149 25450
62271 9177
38892 268598
273853 250782
191939 89247
40...

output:


result: