QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#123226#906. 强连通分量DrGilbert#WA 1ms9532kbC++20936b2023-07-11 21:25:162023-07-11 21:25:18

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-11 21:25:18]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:9532kb
  • [2023-07-11 21:25:16]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N=5e5+10;
int dfn[N],low[N],stk[N],ins[N];
int col[N],top,tot,num;
vector<vector<int>> G,scc;
void tarjan(int x){
	stk[++top]=x;ins[x]=1;
	dfn[x]=low[x]=++tot;
	for (int v:G[x]){
		if (!dfn[v]) tarjan(v),low[x]=min(low[x],low[v]);
		else if (ins[v]) low[x]=min(low[x],dfn[v]);
	}if (dfn[x]==low[x]){
		int k;num++;
		do{
			k=stk[top--];col[k]=num;ins[k]=0;
		}while (k!=x);
	}return;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(nullptr);cout.tie(nullptr);
	int n,m;cin>>n>>m;G.resize(n+10);
	for (int i=1;i<=m;i++){
		int u,v;cin>>u>>v;u++;v++;
		G[u].emplace_back(v);
	}for (int i=1;i<=n;i++){
		if (!dfn[i]) tarjan(i);
	}scc.resize(num+10);
	for (int i=1;i<=n;i++){
		scc[col[i]].emplace_back(i);
	}cout<<num<<endl;
	for (int i=1;i<=num;i++){
		cout<<scc[i].size()<<' ';
		for (int x:scc[i]) cout<<x-1<<' ';
		cout<<endl;
	}return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 9532kb

input:

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

output:

4
2 0 3 
1 2 
2 1 4 
1 5 

result:

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