QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#128911 | #906. 强连通分量 | Acestar# | WA | 4ms | 29336kb | C++14 | 955b | 2023-07-21 16:54:14 | 2023-07-21 16:59:13 |
Judging History
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)