QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#881542#1000. 边三连通分量JohnAlfnovWA 156ms128684kbC++142.4kb2025-02-04 16:34:252025-02-04 16:34:26

Judging History

This is the latest submission verdict.

  • [2025-02-04 16:34:26]
  • Judged
  • Verdict: WA
  • Time: 156ms
  • Memory: 128684kb
  • [2025-02-04 16:34:25]
  • Submitted

answer

#include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
vector<pair<int,int>>g[500005],gg[500005];
int vist[500005];
#define ull unsigned long long
ull yy[500005],yh[500005],hh[500005],hy[500005],seed=13770617;
ull ran(){
	seed^=seed<<7;
	seed^=seed>>13;
	seed^=seed<<17;
	return seed;
}
int dep[500005];
void dfs0(int x,int la){
	vist[x]=1;
	for(auto pi:g[x]){
		int cu=pi.first,c2=pi.second;
		if(cu==c2)continue;
		if(vist[cu]){
			if(dep[cu]<dep[x]){
				yh[c2]=yy[c2];hh[cu]^=yy[c2];hh[x]^=yy[c2];
			}
			continue;
		}
		gg[x].emplace_back(cu,c2);
		dep[cu]=dep[x]+1;
		dfs0(cu,c2);
	}
}
int fa[500005],uu[500005],vv[500005],ok[500005],bg[500005],tot=0;
void dfs1(int x){
	bg[x]=++tot;
	for(auto pi:gg[x]){
		int cu=pi.first,c2=pi.second;
		fa[cu]=x;ok[c2]=1;
		dfs1(cu);
		yh[c2]^=hh[cu];
		hh[x]^=hh[cu];
	}
}
void dfs2(int x){
	for(auto pi:gg[x]){
		int cu=pi.first;
		hy[cu]^=hy[x];
		dfs2(cu);
	}
}
vector<int>gb[500005],g3[500005];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;++i){
		int u,v;
		scanf("%d%d",&u,&v);
++u,++v;
		if(u==v)continue;
		g[u].emplace_back(v,i);
		g[v].emplace_back(u,i);
		uu[i]=u,vv[i]=v;
		yy[i]=ran();
	}
	vector<int>vc;
	for(int i=1;i<=n;++i)if(!vist[i]){
		dfs0(i,0);hy[i]^=ran();dfs1(i);
		vc.emplace_back(i);
	}
	gp_hash_table<ull,int>m1;
	for(int i=1;i<=m;++i){
		if(yh[i]==0){
			if(fa[uu[i]]==vv[i])swap(uu[i],vv[i]);
			hy[vv[i]]^=ran();
			continue;
		}
		if(!ok[i]){
			++m1[yh[i]];
		}
	}
	for(int i=1;i<=m;++i)if(yh[i]&&ok[i]){
		if(fa[uu[i]]==vv[i])swap(uu[i],vv[i]);
		if(m1[yh[i]]==1)hy[vv[i]]^=ran();
	}
	gp_hash_table<ull,int>m2;
	int tt=0;
	for(int i=1;i<=m;++i)if(yh[i]&&ok[i]){
		if(!m2[yh[i]])m2[yh[i]]=++tt;
		gb[m2[yh[i]]].emplace_back(i);
	}
	for(int i=1;i<=tt;++i){
		sort(gb[i].begin(),gb[i].end(),[&](int a,int b){
			return bg[vv[a]]<bg[vv[b]];
		});
		int sz=gb[i].size();
		if(sz<=1)continue;
		for(int j=0;j<sz-1;++j){
			int a=gb[i][j],b=gb[i][j+1];
			ull ul=ran();
			hy[vv[a]]^=ul,hy[vv[b]]^=ul;
		}
	}
	for(auto v:vc){
		dfs2(v);
	}
	gp_hash_table<ull,int>mp;
	int t=0;
	for(int i=1;i<=n;++i){
		if(!mp[hy[i]])mp[hy[i]]=i,++t;
		g3[mp[hy[i]]].emplace_back(i);
	}
	printf("%d\n",t);
	for(int i=1;i<=n;++i)if(g3[i].size()){
printf("%d ",(signed)g3[i].size());
		for(auto cu:g3[i])printf("%d ",cu-1);
		printf("\n");
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 9ms
memory: 69860kb

input:

4 5
0 2
0 1
3 0
2 1
2 3

output:

3
2 0 2 
1 1 
1 3 

result:

ok OK

Test #2:

score: 0
Accepted
time: 4ms
memory: 67736kb

input:

13 21
4 5
8 7
12 3
3 10
1 5
10 2
0 0
11 4
2 12
9 1
9 0
7 8
7 6
9 1
8 2
12 10
11 0
8 6
3 2
5 9
4 11

output:

6
1 0 
3 1 5 9 
4 2 3 10 12 
2 4 11 
1 6 
2 7 8 

result:

ok OK

Test #3:

score: -100
Wrong Answer
time: 156ms
memory: 128684kb

input:

200000 200000
127668 148778
77100 11865
85144 199231
39485 84917
102044 187263
130204 174776
26220 198288
162188 12078
92196 146334
120537 38083
150353 160479
18707 6545
101149 25450
62271 9177
38892 6454
11709 191939
89247 145109
140599 121858
197410 148980
55975 169098
128576 59852
68224 182347
89...

output:

156857
1 0 
9159 1 2 9 12 46 56 99 123 220 270 284 300 305 313 392 396 414 456 471 480 491 601 604 614 670 673 701 739 752 781 792 846 869 874 883 901 921 953 965 969 976 981 994 1004 1006 1018 1036 1037 1046 1103 1120 1149 1190 1191 1197 1213 1221 1245 1285 1288 1318 1350 1361 1389 1407 1412 1452 1...

result:

wrong answer # of tecc is differ - expected: '156853', found: '156857'