QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#791611 | #906. 强连通分量 | rotcar07 | WA | 2ms | 7688kb | C++23 | 872b | 2024-11-28 19:51:26 | 2024-11-28 19:51:26 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
constexpr int maxn=5e5+5;
int dfn[maxn],low[maxn],toki,n,m;
vector<vector<int>> V;
vector<int> e[maxn];
stack<int> st;bool ins[maxn];
void dfs(int p){
dfn[p]=low[p]=++toki;st.push(p);ins[p]=1;
for(int x:e[p]) low[p]=min(low[p],dfn[x]?ins[x]?dfn[x]:int(1e9):(dfs(x),low[x]));
if(dfn[p]==low[p]){
vector<int> tmp;
while(st.top()!=p){
tmp.push_back(st.top());
ins[st.top()]=0;st.pop();
}
tmp.push_back(p);st.pop();ins[p]=0;
V.push_back(tmp);
}
}
int main(){
cin>>n>>m;
for(int i=1,u,v;i<=m;i++) cin>>u>>v,u++,v++,e[u].push_back(v);
for(int i=1;i<=n;i++) if(!dfn[i]) dfs(i);
cout<<V.size()<<'\n';
for(const auto&v:V){
cout<<v.size()<<' ';
for(int x:v) cout<<x-1<<' ';cout<<'\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 7688kb
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)