QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#382969#906. 强连通分量ieeWA 1ms3624kbC++141.0kb2024-04-08 20:34:572024-04-08 20:34:58

Judging History

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

  • [2024-04-08 20:34:58]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3624kb
  • [2024-04-08 20:34:57]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
int main() {
	cin.tie(0)->sync_with_stdio(0);
	int n, m;
	cin >> n >> m;
	vector<vector<int>> e(n);
	for (int i = 0, u, v; i < m; i++) {
		cin >> u >> v;
		e[u].push_back(v);
	}
	vector<int> dfn(n, -1), low(n), ins(n), st;
	int dfc = 0, tot = 0;
	vector<vector<int>> ans;
	function<void(int)> dfs = [&](int u) {
		dfn[u] = low[u] = dfc++;
		ins[u] = 1, st.push_back(u);
		for (int v : e[u]) {
			if (dfn[v] == -1) {
				dfs(v);
				dfn[u] = min(dfn[u], dfn[v]);
			} else if (ins[v]) {
				dfn[u] = min(dfn[u], low[v]);
			}
		}
		if (low[u] == dfn[u]) {
			int ver;
			vector<int> vec;
			do {
				ver = st.back();
				vec.push_back(ver);
				st.pop_back();
				ins[ver] = 0;
			} while (ver != u);
			ans.push_back(vec);
			tot++;
		}
	};
	for (int i = 0; i < n; i++) {
		if (dfn[i] == -1) {
			dfs(i);
		}
	}
	reverse(ans.begin(), ans.end());
	for (auto vec : ans) {
		cout << vec.size();
		for (int x : vec) {
			cout << " " << x;
		}
		cout << "\n";
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

1 5
2 4 1
1 2
2 3 0

result:

wrong answer twice used vertex 1