QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#918721#906. 强连通分量Poetry#WA 0ms3584kbC++261.1kb2025-02-27 22:22:192025-02-27 22:22:30

Judging History

This is the latest submission verdict.

  • [2025-02-27 22:22:30]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3584kb
  • [2025-02-27 22:22:19]
  • Submitted

answer

#include <bits/stdc++.h>

using u32 = unsigned;
using i64 = long long;
using u64 = unsigned long long;

constexpr int N = 2E4 + 5;

int n, m;
int ans;
std::vector<int> adj[N], vec[N];

int dfn[N], low[N], tot, rt;
bool vis[N];
std::stack<int> st;

void dfs(int x) {
	dfn[x] = low[x] = ++tot;
	vis[x] = 1;
	st.push(x);
	for (auto y : adj[x]) {
		if (!dfn[y]) {
			dfs(y);
			low[x] = std::min(low[x], low[y]);
		}
		if (vis[y]) {
			low[x] = std::min(low[x], dfn[y]);
		}
	}
	if (low[x] == dfn[x]) {
		++ans;
		for (int i = 0; i != x; st.pop()) {
			i = st.top();
			vec[ans].push_back(i);
			vis[i] = 0;
		}
	}
}

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

	std::cin >> n >> m;
	for (int i = 1; i <= m; ++i) {
		int u, v;
		std::cin >> u >> v;
		++u, ++v;
		adj[u].push_back(v);
	}

	for (int i = 1; i <= n; ++i)
		if (!dfn[i]) {
			dfs(i);
		}

	std::cout << ans << "\n";
	for (int i = 1; i <= ans; ++i) {
		std::cout << vec[i].size() << " ";
		for (auto x : vec[i])
			std::cout << x - 1 << " \n"[x == vec[i].back()];
	}

	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3584kb

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)