QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#342312 | #906. 强连通分量 | shuopihua# | WA | 2ms | 21788kb | C++14 | 1.2kb | 2024-03-01 10:32:02 | 2024-03-01 10:32:14 |
Judging History
answer
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
int n,m,tm,top,cnt;
int h[500005];
int bl[500005];
int dfn[500005];
int low[500005];
int stk[500005];
bool vis[500005];
vector <int> g[500005];
inline void in(int &n){
n=0;
char c=getchar();
while(c<'0' || c>'9') c=getchar();
while(c>='0'&&c<='9') n=n*10+c-'0',c=getchar();
return ;
}
inline void tarjan(int u){
dfn[u]=low[u]=++tm;
vis[u]=1;
stk[++top]=u;
for(int 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(low[u]==dfn[u]){
cnt++;
while(stk[top]!=u){
bl[stk[top]]=cnt;
vis[stk[top]]=0;
top--;
}
bl[u]=cnt;
vis[u]=0;
top--;
}
return ;
}
int main(){
in(n),in(m);
for(int i=1;i<=m;i++){
int u,v;
in(u),in(v);
g[u].emplace_back(v);
}
for(int i=0;i<n;i++) if(!dfn[i]) tarjan(i);
for(int i=0;i<n;i++) g[i].clear();
printf("%d\n",cnt);
for(int i=0;i<n;i++) g[bl[i]].emplace_back(i);
for(int i=1;i<=cnt;i++){
printf("%d ",(int)g[i].size());
for(int v:g[i]) printf("%d ",v);
puts("");
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 21788kb
input:
6 7 1 4 5 2 3 0 5 5 4 1 0 3 4 2
output:
4 2 0 3 1 2 2 1 4 1 5
result:
wrong answer 5 is later than 2, but there is an edge (5, 2)