QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#92114#906. 强连通分量SoyTony#WA 7ms29300kbC++141.6kb2023-03-30 11:05:552023-03-30 11:05:59

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-30 11:05:59]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:29300kb
  • [2023-03-30 11:05:55]
  • 提交

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)