QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#606309#906. 强连通分量gogo11WA 1ms3824kbC++202.1kb2024-10-03 00:57:042024-10-03 00:57:04

Judging History

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

  • [2024-10-03 00:57:04]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3824kb
  • [2024-10-03 00:57:04]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define all(x) x.begin(),x.end()
constexpr int N = 5e5 + 10;
constexpr int M = 5e5 + 10;
constexpr ll Mod = 998244353;
constexpr int INF = 0x3f3f3f3f;
constexpr ll Base = 1277;
constexpr int MAXBIT = 30;
vector<int> bel[N];
struct SCC {
    int n;
    vector<vector<int>> adj;
    vector<int> stk,dfn,low,col;
    int cur,cnt;
    SCC() {}
    SCC(int n) {init(n);}
    void init(int n) {
        this->n=n;
        adj.assign(n+1,{});dfn.assign(n+1,-1);col.assign(n+1,-1);
        low.resize(n+1);
        stk.clear();
        cur=cnt=0;
    }
    void addEdge(int u,int v) {adj[u].push_back(v);}
    void dfs(int x) {
        dfn[x]=low[x]=cur++;
        stk.push_back(x);
        for (int y: adj[x]) {
            if(dfn[y]==-1) {
                dfs(y);
                low[x]=min(low[x],low[y]);
            } else if(col[y]==-1) {
                low[x]=min(low[x],dfn[y]);
            }
        }
        if(dfn[x]==low[x]) {
            int y;
            cnt+=1;
            do {
                y=stk.back();
                col[y]=cnt;
                stk.pop_back();
            }while(y!=x);
        }
    }
    vector<int> work() {
        for (int i=1;i<=n;i++) if(dfn[i]==-1) dfs(i);
        return col;
    }
    int sccnum() {return cnt;}
};
void solve()
{
    int n,m;
    cin>>n>>m;
    SCC scc(n);
    for(int i=1;i<=m;i++)
    {
        int u,v;
        cin>>u>>v;
        u++,v++;
        scc.addEdge(u,v);
    }
    scc.work();
    cout<<scc.sccnum()<<"\n";
    for(int i=scc.sccnum();i>=1;i--)
    {
        cout<<bel[i].size()<<" ";
        for(int v: bel[i])
            cout<<v-1<<" ";
        cout<<"\n";
    }
}
int main()
{
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("out.txt","w",stdout);
    // #endif
    int _ = 1;
    // cin >> _;
    while (_--)
        solve();
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3824kb

input:

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

output:

4
0 
0 
0 
0 

result:

wrong answer Integer 0 violates the range [1, 6]