QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#480856#906. 强连通分量wanglianda#WA 0ms32492kbC++141.0kb2024-07-16 19:14:102024-07-16 19:14:10

Judging History

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

  • [2024-07-16 19:14:10]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:32492kb
  • [2024-07-16 19:14:10]
  • 提交

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;
		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;
}

详细

Test #1:

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

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)