QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#479795#906. 强连通分量Kalenist#WA 6ms30768kbC++14992b2024-07-15 20:55:082024-07-15 20:55:09

Judging History

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

  • [2024-07-15 20:55:09]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:30768kb
  • [2024-07-15 20:55:08]
  • 提交

answer

#include<bits/stdc++.h>
#define N 500010
#define For(i,a,b) for(register int i=a;i<=b;i++)
using namespace std;
int n,m,dfn[N],cnt;
int low[N],top,sta[N];
bool insta[N];
vector<int> go[N],h[N];
inline void tarjan(int x)
{
    dfn[x]=low[x]=++dfn[0];
    insta[sta[++top]=x]=true;
    for(int to:go[x])
        if(!dfn[to]) tarjan(to),low[x]=min(low[x],low[to]);
        else if(insta[to]) low[x]=min(low[x],dfn[to]);
    if(dfn[x] != low[x]) return;
    cnt++,sta[top+1]=0;
    while(sta[top+1] != x)
    {
        int nw=sta[top--];
        insta[nw]=false;
        h[cnt].push_back(nw);
    }
    return;
}

int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>m;
    For(i,1,m)
    {
        int x,y;cin>>x>>y;
        go[x+1].push_back(y+1);
    }For(i,1,n) if(!dfn[i]) tarjan(i);
    cout<<cnt<<'\n';
    For(i,1,cnt)
    {
        cout<<h[i].size()<<' ';
        for(int x:h[i]) cout<<x-1<<' ';
        cout<<'\n';
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 6ms
memory: 30768kb

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)