QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#479795 | #906. 强连通分量 | Kalenist# | WA | 6ms | 30768kb | C++14 | 992b | 2024-07-15 20:55:08 | 2024-07-15 20:55:09 |
Judging History
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)