QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#129376#906. 强连通分量yixiuge777#WA 8ms30624kbC++141.3kb2023-07-22 17:34:412023-07-22 17:34: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-22 17:34:44]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:30624kb
  • [2023-07-22 17:34:41]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#define ll long long
#define N 500010
using namespace std;
ll read(){
	char cc;
	while(1){cc=getchar();if((cc>='0'&&cc<='9')||cc=='-')break;}
	ll sum=0,flag=1;
	cc=='-'?flag=-1:sum=(cc^48);
	while(1){cc=getchar();if(!(cc>='0'&&cc<='9'))break;sum=(sum<<1)+(sum<<3)+(cc^48);}
	return sum*flag;
}
void write(ll x){
	if(!x)putchar('0');
	if(x<0){x=-x;putchar('-');}
	ll cc[25],cntt=0;
	while(x){cc[++cntt]=x%10;x/=10;}
	for(ll i=cntt;i>=1;i--)putchar(cc[i]+'0');
	putchar(' ');
}
vector<ll>b[N],c[N];
ll n,m,vis[N],q[N],hh=0,shu[N],dfn[N],low[N],tot=0,cnt=0; 
void dfs(ll x){
	dfn[x]=low[x]=++tot;
	q[++hh]=x;vis[x]=1;
	for(ll v:b[x]){
		if(!dfn[v]){dfs(v);low[x]=min(low[x],low[v]);}
		else if(vis[v])low[x]=min(low[x],dfn[v]);
	}
	if(dfn[x]==low[x]){
		cnt++;
		while(q[hh]!=x){c[cnt].push_back(q[hh]);vis[q[hh]]=0;hh--;}
		c[cnt].push_back(q[hh]);vis[q[hh]]=0;hh--;
	}
}
int main(){
//	freopen("data.in","r",stdin);
	n=read();m=read();
	for(ll i=1;i<=m;i++){
		ll u=read(),v=read();
		b[u].push_back(v);
	}
	for(ll i=0;i<n;i++)if(!dfn[i])dfs(i);
	write(cnt);putchar('\n');
	for(ll i=1;i<=cnt;i++){
		write(c[i].size());for(ll v:c[i])write(v);putchar('\n');
	}
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 8ms
memory: 30624kb

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)