QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#93091#906. 强连通分量Thunder_S#WA 1ms19408kbC++141.3kb2023-03-31 10:46:362023-03-31 10:46:37

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-31 10:46:37]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:19408kb
  • [2023-03-31 10:46:36]
  • 提交

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;
}

详细

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)