QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#92114 | #906. 强连通分量 | SoyTony# | WA | 7ms | 29300kb | C++14 | 1.6kb | 2023-03-30 11:05:55 | 2023-03-30 11:05:59 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn=5e5+10;
inline int read(){
int x=0,w=1;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')w=-1;getchar();}
while(c<='9'&&c>='0'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
return x*w;
}
int n,m;
struct Graph{
vector<int> E[maxn];
inline void add_edge(int u,int v){
E[u].push_back(v);
}
int dfn[maxn],dfncnt,low[maxn];
int scc[maxn],scccnt;
vector<int> SCC[maxn];
int st[maxn],top;
void Tarjan(int u){
dfn[u]=++dfncnt,low[u]=dfn[u];
st[++top]=u;
for(int v:E[u]){
if(!dfn[v]){
Tarjan(v);
low[u]=min(low[u],low[v]);
}
else if(!scc[v]) low[u]=min(low[u],dfn[v]);
}
if(dfn[u]==low[u]){
++scccnt;
while(st[top]!=u){
scc[st[top]]=scccnt;
SCC[scccnt].push_back(st[top]);
--top;
}
scc[u]=scccnt;
SCC[scccnt].push_back(u);
--top;
}
}
inline void solve(){
for(int u=1;u<=n;++u){
if(!dfn[u]) Tarjan(u);
}
printf("%d\n",scccnt);
for(int i=1;i<=scccnt;++i){
printf("%ld ",SCC[i].size());
for(int u:SCC[i]) printf("%d ",u-1);
printf("\n");
}
}
}G;
int main(){
n=read(),m=read();
for(int i=1;i<=m;++i){
int u=read()+1,v=read()+1;
G.add_edge(u,v);
}
G.solve();
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 7ms
memory: 29300kb
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)