QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#340747#906. 强连通分量ffffyc#WA 3ms15340kbC++141.8kb2024-02-29 11:43:002024-02-29 11:43:03

Judging History

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

  • [2024-02-29 11:43:03]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:15340kb
  • [2024-02-29 11:43:00]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
namespace IO{//by cyffff
	int len=0;
	char ibuf[(1<<21)+1],*iS,*iT,out[(1<<25)+1];
	#if ONLINE_JUDGE
	#define gh() (iS==iT?iT=(iS=ibuf)+fread(ibuf,1,(1<<21)+1,stdin),(iS==iT?EOF:*iS++):*iS++)
 	#else
	#define gh() getchar()
	#endif
	#define reg register
	inline int read(){
		reg char ch=gh();
		reg int x=0;
		reg char t=0;
		while(ch<'0'||ch>'9')   t|=ch=='-',ch=gh();
		while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=gh();
		return t?-x:x;
	}
	inline void putc(char ch){
		out[len++]=ch;
	}
	template<class T>
	inline void write(T x){
		if(x<0)putc('-'),x=-x;
		if(x>9)write(x/10);
		out[len++]=x%10+48;
	}
	inline void flush(){
		fwrite(out,1,len,stdout);
		len=0;
	}
	inline char getc(){
		char ch=gh();
		while(ch<'A'||ch>'Z') ch=gh();
		return ch;
	}
}
using IO::read;
using IO::write;
using IO::flush;
using IO::getc;
using IO::putc;
const int N=5e5+10;
int n,m,head[N],cnt;
struct Edge{
	int to,nxt;
}a[N<<1];
inline void add(int u,int v){
	a[++cnt]={v,head[u]},head[u]=cnt;
}
int dfn[N],low[N],tim,stk[N],top,blk;
bool vis[N];
vector<int>poi[N];
inline void Tarjan(int x){
	low[x]=dfn[x]=++tim;
	stk[++top]=x,vis[x]=1;
	int sc=0;
	for(int i=head[x];i;i=a[i].nxt){
		int t=a[i].to;
		if(!dfn[t]){
			Tarjan(t);
			low[x]=min(low[x],low[t]);
		}else if(vis[t]) low[x]=min(low[x],dfn[t]);
	}
	if(dfn[x]==low[x]){
		blk++;
		while(1){
			int p=stk[top--];
			vis[p]=0;
			poi[blk].push_back(p);
			if(p==x) break;
		}
	}
}
int main(){
	n=read(),m=read();
	for(int i=1;i<=m;i++){
		int u=read()+1,v=read()+1;
		add(u,v);
	}
	for(int i=1;i<=n;i++)
		if(!dfn[i])
			Tarjan(i);
	write(blk),putc('\n');
	for(int i=1;i<=blk;i++){
		write(poi[i].size()),putc(' ');
		for(auto tmp:poi[i]) write(tmp-1),putc(' ');
		putc('\n');
	}
	flush();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 15340kb

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)