QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#482099 | #906. 强连通分量 | Doqe | WA | 0ms | 53600kb | C++14 | 777b | 2024-07-17 17:15:10 | 2024-07-17 17:15:10 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
vector<int>scc[N],to[N];
int dfn[N],low[N],tt,in[N],cnt;
int sta[N],top;
void tarjan(int u)
{
sta[++top]=u,in[u]=1;
dfn[u]=++tt,low[u]=tt;
for(int v:to[u])
if(!dfn[v])tarjan(v),low[u]=min(low[u],low[v]);
else if(in[v])low[u]=min(low[u],dfn[v]);
if(dfn[u]==low[u])
{
int k;++cnt;
do
{
k=sta[top--];in[k]=0;
scc[cnt].push_back(k);
}while(k!=u);
}
}
int main()
{
cin.tie(0)->sync_with_stdio(0);
int n,m;cin>>n>>m;
for(int i=1;i<=m;++i)
{
int u,v;cin>>u>>v;
to[u].push_back(v);
}
for(int i=0;i<n;++i)
if(!dfn[i])tarjan(i);
cout<<cnt<<"\n";
for(int i=1;i<=cnt;++i)
{
cout<<scc[i].size();
for(int j:scc[i])cout<<" "<<j;cout<<"\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 53600kb
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)