QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#92682 | #906. 强连通分量 | zhangboju# | WA | 4ms | 29512kb | C++14 | 1.1kb | 2023-03-30 20:51:14 | 2023-03-30 20:51:17 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
template <typename T> inline void read(T &x)
{
x=0;short f=1;char c=getchar();
for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
for(;c>='0'&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48);
x*=f;return;
}
const int N=5e5+5;
int n,m;
vector<int>g[N];
int dfn[N],low[N],dfs_clock;
int stk[N],top;
bool in_stk[N];
int scc_cnt;
vector<int>ve[N];
void tarjan(int u)
{
dfn[u]=low[u]=++dfs_clock;
stk[++top]=u,in_stk[u]=1;
for(int v:g[u])
{
if(!dfn[v])
{
tarjan(v);
low[u]=min(low[u],low[v]);
}
else if(in_stk[v]) low[u]=min(low[u],dfn[v]);
}
if(dfn[u]==low[u])
{
++scc_cnt;
int y;
do{
y=stk[top--];
in_stk[y]=0;
ve[scc_cnt].push_back(y);
}while(y!=u);
}
}
int main()
{
read(n),read(m);
for(int i=1;i<=m;++i)
{
int u,v;read(u),read(v);
g[u].push_back(v);
}
for(int i=0;i<n;++i)
if(!dfn[i]) tarjan(i);
printf("%d\n",scc_cnt);
for(int i=1;i<=scc_cnt;++i)
{
printf("%d ",ve[i].size());
for(int x:ve[i]) printf("%d ",x);
puts("");
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 29512kb
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)