QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#93091 | #906. 强连通分量 | Thunder_S# | WA | 1ms | 19408kb | C++14 | 1.3kb | 2023-03-31 10:46:36 | 2023-03-31 10:46:37 |
Judging History
answer
#include<cstdio>
#include<vector>
#define N 500005
using namespace std;
int n,m,tot,cnt,top,num,dfn[N],low[N],sta[N],col[N];
struct node {int to,next,head;}a[N<<1];
vector<int> f[N];
int min(int x,int y) {return x<y?x:y;}
void add(int x,int y) {a[++tot].to=y;a[tot].next=a[x].head;a[x].head=tot;}
void dfs(int x)
{
dfn[x]=low[x]=++cnt;
sta[++top]=x;
for (int i=a[x].head;i;i=a[i].next)
{
int y=a[i].to;
if (!dfn[y])
{
dfs(y);
low[x]=min(low[x],low[y]);
}
else if (!col[y]) low[x]=min(low[x],dfn[y]);
}
if (low[x]==dfn[x])
{
col[x]=++num;f[num].push_back(x);
while (sta[top]!=x)
{
f[num].push_back(sta[top]);
col[sta[top--]]=num;
}
top--;
}
}
int main()
{
scanf("%d%d",&n,&m);
for (int i=1;i<=m;++i)
{
int x,y;
scanf("%d%d",&x,&y);++x;++y;
add(x,y);
}
for (int i=1;i<=n;++i)
if (!dfn[i])
dfs(i);
printf("%d\n",num);
for (int i=1;i<=num;++i)
{
printf("%d ",f[i].size());
for (int j=0;j<f[i].size();++j)
printf("%d ",f[i][j]-1);
printf("\n");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 19408kb
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)