QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#382969 | #906. 强连通分量 | iee | WA | 1ms | 3624kb | C++14 | 1.0kb | 2024-04-08 20:34:57 | 2024-04-08 20:34:58 |
Judging History
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;
}
详细
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