QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#474036 | #906. 强连通分量 | wangzhifang# | WA | 4ms | 16564kb | C++14 | 1.1kb | 2024-07-12 15:42:10 | 2024-07-12 15:42:10 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
constexpr int inf_int=numeric_limits<int>::max();
constexpr int max_n=500000;
vector<int>g[max_n+1];
int low[max_n+1];
int stk[max_n+1],dfncnt,stkcnt;
vector<vector<int> >comps;
int dfsa(const int u){
const int dfu=low[u]=++dfncnt;
stk[++stkcnt]=u;
int lwu=dfu;
for(const int&v:g[u]){
if(low[v]){
if(low[v]<lwu)
lwu=low[v];
continue;
}
const int lwv=dfsa(v);
if(lwv<lwu)
lwu=lwv;
}
if(dfu==lwu){
vector<int>vec;
for(int v; (v=stk[stkcnt])!=u; --stkcnt)
vec.emplace_back(v),low[v]=inf_int;
vec.emplace_back(u),low[u]=inf_int,--stkcnt;
comps.emplace_back(vec);
}
return low[u]=lwu;
}
int main(){
int n,m;
scanf("%d%d",&n,&m);
for(int i=1,u,v; i<=m; ++i){
scanf("%d%d",&u,&v);
g[u].emplace_back(v);
}
for(int i=0; i<n; ++i)
if(!low[i])
dfsa(i);
printf("%zd\n",comps.size());
for(decltype(comps)::const_reverse_iterator it=comps.crbegin(),ed=comps.crend(); it!=ed; ++it){
printf("%zd",it->size());
for(const int&x:*it)
printf(" %d",x);
putchar('\n');
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 16564kb
input:
6 7 1 4 5 2 3 0 5 5 4 1 0 3 4 2
output:
3 2 4 1 1 2 2 3 0
result:
wrong answer # of scc is differ - expected: '4', found: '3'