QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#128911#906. 强连通分量Acestar#WA 4ms29336kbC++14955b2023-07-21 16:54:142023-07-21 16:59:13

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-21 16:59:13]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:29336kb
  • [2023-07-21 16:54:14]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 5e5 + 5;

int n, m, cnt;
vector<int> G[N];

int tim, dfn[N], low[N];
bool vis[N];
int tp, st[N];
vector<int> scc[N];

void tarjan(int u)
{
	dfn[u] = low[u] = ++tim;
	vis[u] = 1;
	st[++tp] = u;
	for(auto v : G[u])
	{
		if(!dfn[v]) tarjan(v), low[u] = min(low[u], low[v]);
		else if(vis[v]) low[u] = min(low[u], dfn[v]);
	}
	if(dfn[u] == low[u])
	{
		int x; cnt++;
		do{x = st[tp--], vis[x] = 0, scc[cnt].push_back(x);}
		while(x != u);
	}
	return;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);

	cin >> n >> m;
	for(int i = 1, u, v; i <= m; i++)
		cin >> u >> v, G[u + 1].push_back(v + 1);
	for(int i = 1; i <= n; i++) if(!dfn[i]) tarjan(i);
	cout << cnt << '\n';
	for(int i = 1; i <= cnt; i++)
	{
		cout << scc[i].size() << ' ';
		for(auto x : scc[i]) cout << x - 1 << ' ';
		cout << '\n';
	}
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 29336kb

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)