QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#398556#4686. Toursjinqihao2023WA 1ms4268kbC++141.3kb2024-04-25 15:01:122024-04-25 15:01:12

Judging History

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

  • [2024-04-25 15:01:12]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4268kb
  • [2024-04-25 15:01:12]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=2e3+5;
typedef unsigned long long ull;
int n,m,d[N],num[N],fa[N];
ull val[N];
vector<int>son[N],son1[N];
bool vis[N];
mt19937_64 rd(time(0));
int ans;
void dfs1(int x,int prt)
{
	vis[x]=1;
	for(auto y:son[x])if(!vis[y])d[y]=d[x]+1,son1[x].push_back(y),fa[y]=x,dfs1(y,x);else if(d[y]<d[x] && y!=prt)
	{
		ans=__gcd(ans,d[x]-d[y]+1);
		ull v=rd();
		val[x]^=v,val[y]^=v,num[x]++,num[y]--;
	}
}
void dfs2(int x)
{
	for(auto y:son1[x])dfs2(y),val[x]^=val[y],num[x]+=num[y];
}
int prt[N],sz[N];
int gf(int x){if(x==prt[x])return x;return prt[x]=gf(prt[x]);}
void merge(int x,int y){x=gf(x),y=gf(y);if(x!=y)prt[x]=y,sz[y]+=sz[x];}
int main()
{
	scanf("%d %d",&n,&m);
	for(int i=1,x,y;i<=m;i++)scanf("%d %d",&x,&y),son[x].push_back(y),son[y].push_back(x);
	for(int i=1;i<=n;i++)if(!vis[i])dfs1(i,0),dfs2(i);
	for(int i=1;i<=n;i++)prt[i]=i,sz[i]=(num[i]>1);
	for(int i=1;i<=n;i++)
	{
		map<ull,vector<int> >mp;
		for(auto j:son1[i])mp[val[j]].push_back(j);
		if(fa[i])mp[val[i]].push_back(i);
		for(auto j:mp)for(auto k:j.second)merge(k,j.second[0]);
	}
	for(int i=1;i<=n;i++)if(prt[i]==i && sz[i])ans=__gcd(ans,sz[i]);
	for(int i=1;i<=n;i++)if(ans%i==0)printf("%d ",i);printf("\n");
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3984kb

input:

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

output:

1 

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3976kb

input:

6 6
1 2
2 3
1 3
1 4
2 5
3 6

output:

1 3 

result:

ok 2 number(s): "1 3"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3972kb

input:

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

output:

1 

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3988kb

input:

6 6
1 2
2 3
1 4
2 5
1 3
3 6

output:

1 3 

result:

ok 2 number(s): "1 3"

Test #5:

score: 0
Accepted
time: 0ms
memory: 4016kb

input:

9 10
1 2
2 3
3 4
4 5
5 6
6 7
7 8
1 8
4 9
6 9

output:

1 2 

result:

ok 2 number(s): "1 2"

Test #6:

score: 0
Accepted
time: 0ms
memory: 3952kb

input:

6 7
1 2
2 3
3 4
4 5
5 6
1 6
3 6

output:

1 

result:

ok 1 number(s): "1"

Test #7:

score: -100
Wrong Answer
time: 1ms
memory: 4268kb

input:

33 36
2 22
12 18
27 28
9 19
26 27
6 21
15 16
2 3
7 24
3 12
4 23
28 29
5 14
29 30
1 10
11 13
6 13
16 25
14 21
4 16
10 19
10 11
5 15
1 8
3 20
7 13
25 26
29 31
17 23
8 18
12 24
25 30
31 32
17 20
15 22
9 18

output:

1 

result:

wrong answer Answer contains longer sequence [length = 2], but output contains 1 elements