QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#473888#906. 强连通分量windviolet#WA 0ms6588kbC++141.2kb2024-07-12 14:49:592024-07-12 14:49:59

Judging History

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

  • [2024-07-12 14:49:59]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:6588kb
  • [2024-07-12 14:49:59]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int INF=1e18+9;
const int N=1e5+5;
struct Edge{
	int v,c,nxt;
}e[N<<1];
int h[N],tot;
void add(int u,int v){
	tot++;
	e[tot].v=v;
	e[tot].nxt=h[u];
	h[u]=tot;
}
struct Vertex{
	int dfn,low,vis;
}ver[N];
int q[N],l=1,r=0;
int dfncnt=0;
vector<int>sta[N];
int stacnt=0;
int n,m;
void tarjan(int start){
	ver[start].dfn=++dfncnt;
	ver[start].low=dfncnt;
	q[++r]=start;
	ver[start].vis=1;
	for(int i=h[start];i;i=e[i].nxt){
		int v=e[i].v;
		if(!ver[v].dfn){
			tarjan(v);
			ver[start].low=min(ver[start].low,ver[v].low);
		}
		else if(ver[v].vis){
			ver[start].low=min(ver[start].low,ver[v].dfn);
		}
	}
	if(ver[start].dfn==ver[start].low){
		stacnt++;
		while(l<=r){
			int u=q[r--];
			sta[stacnt].push_back(u);
			ver[u].vis=0;
			if(u==start)break;
		}
	}
}
signed main(){
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=m;i++){
		int u,v;
		scanf("%lld%lld",&u,&v);
		add(u,v);
	} 
	for(int i=0;i<n;i++){
		if(!ver[i].dfn)tarjan(i);
	}
	cout<<stacnt<<"\n";
	for(int i=1;i<=stacnt;i++){
		int lenn=sta[i].size();
		cout<<lenn<<" ";
		for(int j=1;j<=lenn;j++)cout<<sta[i][j-1]<<" ";
		cout<<"\n";
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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)