QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#649085#906. 强连通分量lngsctrerWA 2ms8516kbC++141.3kb2024-10-17 21:33:332024-10-17 21:33:34

Judging History

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

  • [2024-10-17 21:33:34]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:8516kb
  • [2024-10-17 21:33:33]
  • 提交

answer

#include<bits/stdc++.h>
using i64 = long long;
const int N = 200010;
int read(){
	int x = 0, f = 1, c = getchar();
	while(!isdigit(c)){
		if(c == '-') f = -1;
		c = getchar();
	}
	while(isdigit(c)){
		x = x * 10 + (c ^ 48);
		c = getchar();
	}
	return x * f;
}
int n, m;
std::vector<int> E[N];
int low[N], dfn[N], vis[N], dfncnt, st[N], tp;
std::vector<std::vector<int> > ans;
void tarjan(int x, int f){
	low[x] = dfn[x] = ++ dfncnt, vis[x] = 1;
	st[++ tp] = x;
	for(int to : E[x]){
		if(!dfn[to]){
			tarjan(to, x);
			low[x] = std::min(low[x], low[to]);
		}else if(vis[to]) low[x] = std::min(low[x], dfn[to]);
	}
	if(dfn[x] == low[x]){
		std::vector<int> tmp;
		while(st[tp] != x && tp){
			tmp.push_back(st[tp]);
			vis[st[tp]] = 0;
			tp --;	
		}
		tmp.push_back(st[tp]);
		vis[st[tp]] = 0;
		tp --;
		ans.push_back(tmp);
	}
}
void solve(){
	n = read(), m = read();
	for(int i = 1; i <= m;i ++){
		int x = read(), y = read();
		E[x].push_back(y);
	}
	for(int i = 0; i < n; i ++){
		if(!dfn[i]) tarjan(i, i);
	}
	int col = ans.size();
	std::cout << col << '\n';
	for(std::vector<int> inp : ans){
		std::cout << inp.size() << " ";
		for(int x : inp){
			std::cout << x << " ";
		}
		std::cout << '\n';
	}
}
signed main(){
	solve();
	return 0;
}



详细

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 8516kb

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)