QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#480952#906. 强连通分量wanglianda#WA 6ms31660kbC++141.1kb2024-07-16 19:48:452024-07-16 19:48:45

Judging History

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

  • [2024-07-16 19:48:45]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:31660kb
  • [2024-07-16 19:48:45]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=5e5;
ll read(){
	ll S=0,F=1;char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-')F*=-1;
		ch=getchar();
	}while(isdigit(ch)){
		S=(S<<3)+(S<<1)+(ch^48);
		ch=getchar();
	}return S*F;
}ll n,m,u,v,lts,tp,sta[N+10],vis[N+10],dfn[N+10],low[N+10],cnt;
vector<ll >vs[N+10],to[N+10];
void dfs(ll id){
	low[id]=dfn[id]=++cnt;
	sta[++tp]=id;vis[id]=1;
	for(ll i=0;i<to[id].size();i++){
		if(!dfn[to[id][i]]){
			dfs(to[id][i]);
			low[id]=min(low[id],low[to[id][i]]);
		}else if(vis[to[id][i]])low[id]=min(low[id],dfn[to[id][i]]);
	}if(low[id]==dfn[id]){
		lts++;do{
			vs[lts].push_back(sta[tp--]);
			vis[sta[tp+1]]=0;
		}while(sta[tp+1]!=id);
	}return;
}int main(){
	n=read();m=read();
	while(m--){
		u=read()+1;v=read()+1;
//		swap(u,v);
		to[u].push_back(v);
	}for(ll i=1;i<=n;i++)if(!dfn[i])dfs(i);
	printf("%lld\n",lts);
	for(ll i=1;i<=lts;i++){
		printf("%lld ",vs[i].size());
		for(ll j=0;j<vs[i].size();j++)printf("%lld ",vs[i][j]-1);
		putchar('\n');
	}return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 6ms
memory: 31660kb

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)