QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#676821#906. 强连通分量lsj2009WA 1ms5964kbC++201.9kb2024-10-26 01:04:312024-10-26 01:04:31

Judging History

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

  • [2024-10-26 01:04:31]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5964kb
  • [2024-10-26 01:04:31]
  • 提交

answer

#include<bits/stdc++.h>
//#pragma GCC optimize(3,"Ofast","inline")
//#define int long long
#define i128 __int128
#define ll long long
#define ull unsigned long long
#define uint unsigned int
#define ld double
#define PII pair<int,int>
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f
#define chkmax(a,b) a=max(a,b)
#define chkmin(a,b) a=min(a,b)
#define rep(k,l,r) for(int k=l;k<=r;++k)
#define per(k,r,l) for(int k=r;k>=l;--k)
#define cl(f,x) memset(f,x,sizeof(f))
#define pcnt(x) __builtin_popcount(x)
#define lg(x) (31-__builtin_clz(x))
using namespace std;
void file_IO() {
//	system("fc .out .ans");
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
}
bool M1;
const int N=5e5+5;
int head[N],len;
struct node {
	int to,nxt;
}; node edge[N];
void add_edge(int u,int v) {
	edge[++len]={v,head[u]}; head[u]=len;
}
int dfn[N],low[N],p;
vector<vector<int>> vec;
stack<int> st;
bool inst[N];
void tarjan(int u) {
	low[u]=dfn[u]=++p;
	st.push(u);
	inst[u]=true;
	for(int i=head[u];i;i=edge[i].nxt) {
		int v=edge[i].to;
		if(!dfn[v]) {
			tarjan(v);
			chkmin(low[u],low[v]);
		} else if(inst[v])
			chkmin(low[u],dfn[v]);
	}
	if(low[u]==dfn[u]) {
		vector<int> t;
		int x=0;
		while(x!=u) {
			x=st.top(); st.pop();
			inst[x]=false;
			t.push_back(x);
		}
		vec.push_back(t);
	}
}
void solve() {
	int n,m;
	scanf("%d%d",&n,&m);
	while(m--) {
		int u,v;
		scanf("%d%d",&u,&v);
		++u; ++v;
		add_edge(u,v);
	}
	rep(i,1,n) {
		if(!dfn[i])
			tarjan(i);
	}
	printf("%d\n",(int)vec.size());
	for(auto x:vec) {
		printf("%d ",(int)x.size());
		for(auto u:x)
			printf("%d ",u-1);
		puts("");
	}
}
bool M2;
signed main() {
	//file_IO();
	int testcase=1;
	//scanf("%d",&testcase);
	while(testcase--)
		solve();
	fprintf(stderr,"used time = %ldms\n",1000*clock()/CLOCKS_PER_SEC);
	fprintf(stderr,"used memory = %lldMB\n",(&M2-&M1)/1024/1024);
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5964kb

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)