QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#474027 | #906. 强连通分量 | wangzhifang# | WA | 177ms | 51920kb | C++14 | 1.1kb | 2024-07-12 15:36:55 | 2024-07-12 15:36:55 |
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;
vector<vector<int> >comps;
int dfsa(const int u){
const int dfu=low[u]=++dfncnt;
stk[dfu]=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[dfncnt])!=u; --dfncnt)
vec.emplace_back(v),low[v]=inf_int;
vec.emplace_back(u),low[u]=inf_int,--dfncnt;
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 17336kb
input:
6 7 1 4 5 2 3 0 5 5 4 1 0 3 4 2
output:
4 1 5 2 4 1 1 2 2 3 0
result:
ok OK
Test #2:
score: -100
Wrong Answer
time: 177ms
memory: 51920kb
input:
500000 500000 389812 410922 255712 339244 274009 248522 347288 199231 235313 301629 469588 84917 364188 449407 392348 436920 26220 198288 162188 468965 274222 92196 463222 408478 231663 467768 382681 38083 412497 160479 280851 268689 101149 25450 62271 9177 38892 268598 273853 250782 191939 89247 40...
output:
445507 1 499999 1 499995 1 499994 1 499989 1 499988 1 499987 1 499983 1 499978 1 499975 1 499972 1 499969 1 499965 1 499964 1 499954 1 499949 1 499947 1 499942 1 499939 1 499932 1 499928 1 499926 1 499925 1 499924 1 499919 1 499918 1 499915 1 499910 1 499909 1 499907 1 499906 1 499904 1 499903 1 499...
result:
wrong answer # of scc is differ - expected: '499590', found: '445507'