QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#789687#906. 强连通分量_TLEer_#WA 0ms32324kbC++141002b2024-11-27 21:28:032024-11-27 21:28:05

Judging History

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

  • [2024-11-27 21:28:05]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:32324kb
  • [2024-11-27 21:28:03]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
int n,m,u[500010],v[500010];
vector<int> a[500010];vector<int> col[500010];
int dfn[500010],low[500010],bel[500010],tmc,colsz;
int stk[500010],stktp;bool inst[500010];
void dfs(int nw){
	dfn[nw]=low[nw]=++tmc;
	stk[++stktp]=nw;inst[nw]=1;
	for(auto v:a[nw]){
		if(!dfn[v]){
			dfs(v);
			low[nw]=min(low[nw],low[v]);
		}
		else if(inst[v])low[nw]=min(low[nw],dfn[v]);
	}
	if(dfn[nw]==low[nw]){
		++colsz;
		do{
			col[colsz].emplace_back(stk[stktp]);
			bel[stk[stktp]]=colsz;
			inst[stk[stktp]]=0;
		}while(stk[stktp--]!=nw);
	}
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie();cout.tie();
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>u[i]>>v[i];
		u[i]++;v[i]++;
		a[u[i]].emplace_back(v[i]);
	}
	for(int i=1;i<=n;i++)
		if(!dfn[i])dfs(i);
	cout<<colsz<<'\n';
	for(int i=1;i<=colsz;i++){
		cout<<col[i].size()<<' ';
		for(int v:col[i])cout<<v-1<<' ';
		cout<<'\n';
	}
	return 0;
}

详细

Test #1:

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

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)