QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#64838 | #906. 强连通分量 | LinkZelda# | WA | 6ms | 15364kb | C++14 | 1.3kb | 2022-11-25 18:45:03 | 2022-11-25 18:45:05 |
Judging History
answer
#include<bits/stdc++.h>
#define pr pair<int,int>
#define eps 1e-7
#define vt vector<int>
using namespace std;
inline int read()
{
int x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
const int N=500005;
int head[N],to[N],nxt[N],cnt;
void add(int u,int v)
{
to[++cnt]=v;
nxt[cnt]=head[u];
head[u]=cnt;
}
int dfsn[N],low[N],dfscnt;
int scc[N],sta[N],tp,tot,n,m;
bool vis[N];
vt qwq[N];
void tarjan(int now)
{
vis[now]=1;sta[++tp]=now;
low[now]=dfsn[now]=++dfscnt;
for(int i=head[now];i;i=nxt[i])
{
int v=to[i];
if(!dfsn[v])
tarjan(v),low[now]=min(low[now],low[v]);
else if(vis[v])
low[now]=min(low[now],low[v]);
}
if(dfsn[now]==low[now])
{
++tot;
while(tp&&sta[tp]!=now)
qwq[tot].push_back(sta[tp]),vis[sta[tp]]=0,scc[sta[tp--]]=tot;
qwq[tot].push_back(sta[tp]),vis[sta[tp]]=0,scc[sta[tp--]]=tot;
}
}
int main()
{
n=read(),m=read();
for(int u,v,i=1;i<=m;i++)
u=read()+1,v=read()+1,add(u,v);
for(int i=1;i<=n;i++)
if(!dfsn[i])
tarjan(i);
printf("%d\n",tot);
for(int i=1;i<=tot;i++,puts(""))
{
printf("%d ",(int)qwq[i].size());
for(int x:qwq[i])
printf("%d ",x-1);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 6ms
memory: 15364kb
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)