QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#918721 | #906. 强连通分量 | Poetry# | WA | 0ms | 3584kb | C++26 | 1.1kb | 2025-02-27 22:22:19 | 2025-02-27 22:22:30 |
Judging History
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)