QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#640440#906. 强连通分量Zhou_JKRE 1ms5916kbC++231.4kb2024-10-14 12:34:062024-10-14 12:34:06

Judging History

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

  • [2024-10-14 12:34:06]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:5916kb
  • [2024-10-14 12:34:06]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<vector>
#include<bitset>
using namespace std;
constexpr int N=50005;
int n,m;
bitset<N>mp[N],rmp[N];
bitset<N>vis;
int out[N],ind;
void dfs(int x)
{
    bitset<N> now;vis[x]=1;
    for(now=mp[x]^(mp[x]&vis);now.any();now=mp[x]^(mp[x]&vis))
        dfs(now._Find_first());
    out[++ind]=x;
}
vector<int>pos;
vector<vector<int>>block;
int tot;
void dfsrev(int x)
{
    pos.push_back(x);
    bitset<N> now;vis[x]=1;
    for(now=rmp[x]^(rmp[x]&vis);now.any();now=rmp[x]^(rmp[x]&vis))
    {
        dfsrev(now._Find_first());
    }
    return;
}
int kosaraju()
{
    vis.reset();ind=0;
    for(int i=1;i<=n;++i) if(!vis[i]) dfs(i);
    vis.reset();int res=0;
    for(int i=n,x;i;--i) if(!vis[out[i]])
    {
        pos.clear();
        dfsrev(out[i]);
        tot++;
        block.emplace_back(pos);
    }
    return res;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr),cout.tie(nullptr);
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        int u,v;
        cin>>u>>v;
        u++,v++;
        mp[u][v]=1;
        rmp[v][u]=1;
    }
    cerr<<"ed\n";
    kosaraju();
    cout<<tot<<"\n";
    for(int i=0;i<tot;i++)
    {
        int l=block[i].size();
        cout<<l;
        for(int u:block[i])
            cout<<" "<<u-1;
        cout<<"\n";
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5916kb

input:

6 7
1 4
5 2
3 0
5 5
4 1
0 3
4 2

output:

4
1 5
2 1 4
1 2
2 0 3

result:

ok OK

Test #2:

score: -100
Runtime Error

input:

500000 500000
389812 410922
255712 339244
274009 248522
347288 199231
235313 301629
469588 84917
364188 449407
392348 436920
26220 198288
162188 468965
274222 92196
463222 408478
231663 467768
382681 38083
412497 160479
280851 268689
101149 25450
62271 9177
38892 268598
273853 250782
191939 89247
40...

output:


result: