QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#128153#906. 强连通分量AFewSuns#WA 0ms18576kbC++142.2kb2023-07-20 16:51:432023-07-20 16:51:44

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-20 16:51:44]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:18576kb
  • [2023-07-20 16:51:43]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
namespace my_std{
	#define ll long long
	#define bl bool
	ll my_pow(ll a,ll b,ll mod){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res=(res*a)%mod;
			a=(a*a)%mod;
			b>>=1;
		}
		return res;
	}
	ll qpow(ll a,ll b){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res*=a;
			a*=a;
			b>>=1;
		}
		return res;
	}
	#define db double
	#define pf printf
	#define pc putchar
	#define fr(i,x,y) for(register ll i=(x);i<=(y);i++)
	#define pfr(i,x,y) for(register ll i=(x);i>=(y);i--)
	#define go(u) for(ll i=head[u];i;i=e[i].nxt)
	#define enter pc('\n')
	#define space pc(' ')
	#define fir first
	#define sec second
	#define MP make_pair
	#define il inline
	#define inf 1e18
	#define random(x) rand()*rand()%(x)
	#define inv(a,mod) my_pow((a),(mod-2),(mod))
	il ll read(){
		ll sum=0,f=1;
		char ch=0;
		while(!isdigit(ch)){
			if(ch=='-') f=-1;
			ch=getchar();
		}
		while(isdigit(ch)){
			sum=sum*10+(ch^48);
			ch=getchar();
		}
		return sum*f;
	}
	il void write(ll x){
		if(x<0){
			x=-x;
			pc('-');
		}
		if(x>9) write(x/10);
		pc(x%10+'0');
	}
	il void writeln(ll x){
		write(x);
		enter;
	}
	il void writesp(ll x){
		write(x);
		space;
	}
}
using namespace my_std;
vector<ll> vec[500050];
ll n,m,head[500050],cnt=0;
ll dfn[500050],low[500050],tot=0,blg[500050],tott=0,st[500050],top=0;
bl ck[500050];
struct node{
	ll nxt,to;
}e[500050];
void add(ll u,ll v){
	e[++cnt].nxt=head[u];
	e[cnt].to=v;
	head[u]=cnt;
}
void tarjan(ll u){
	dfn[u]=low[u]=++tot;
	st[++top]=u;
	ck[u]=1;
	go(u){
		ll v=e[i].to;
		if(!dfn[v]){
			tarjan(v);
			low[u]=min(low[u],low[v]);
		}
		else if(ck[v]) low[u]=min(low[u],dfn[v]);
	}
	if(dfn[u]==low[u]){
		blg[u]=++tott;
		ck[u]=0;
		while(st[top]!=u){
			blg[st[top]]=tott;
			ck[st[top]]=0;
			top--;
		}
		top--;
	}
}
int main(){
	n=read();
	m=read();
	fr(i,1,m){
		ll u=read()+1,v=read()+1;
		add(u,v);
	}
	fr(i,1,n) if(!dfn[i]) tarjan(i);
	fr(i,1,n) vec[blg[i]].push_back(i);
	writeln(tott);
	fr(i,1,tott){
		writesp((ll)vec[i].size());
		fr(j,0,(ll)vec[i].size()-1) writesp(vec[i][j]-1);
		enter;
	}
}

详细

Test #1:

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

input:

6 7
1 4
5 2
3 0
5 5
4 1
0 3
4 2

output:

4
2 0 3 
1 2 
2 1 4 
1 5 

result:

wrong answer 5 is later than 2, but there is an edge (5, 2)