QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#64838#906. 强连通分量LinkZelda#WA 6ms15364kbC++141.3kb2022-11-25 18:45:032022-11-25 18:45:05

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-25 18:45:05]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:15364kb
  • [2022-11-25 18:45:03]
  • 提交

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)