QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#789082#4686. Toursb6e0WA 0ms3948kbC++14580b2024-11-27 19:14:062024-11-27 19:14:09

Judging History

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

  • [2024-11-27 19:14:09]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3948kb
  • [2024-11-27 19:14:06]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
constexpr int MN=2005;
int n,m,c[MN],fa[MN],ans;
vector<int>g[MN];
void dfs(int x)
{
	for(int y:g[x])
		if(!c[y])
		{
			c[y]=c[x]+1;
			fa[y]=x;
			dfs(y);
		}
}
int main()
{
	scanf("%d%d",&n,&m);
	while(m--)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
	c[1]=1,dfs(1);
	for(int x=1;x<=n;x++)
		for(int y:g[x])
			if(y!=fa[x]&&fa[y]!=x)
				ans=__gcd(ans,abs(c[x]-c[y])+1);
	for(int i=1;i<=ans;i++)
		if(ans%i==0)
			printf("%d ",i);
	putchar('\n');
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3876kb

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: 3948kb

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: 3936kb

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: 3872kb

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: -100
Wrong Answer
time: 0ms
memory: 3948kb

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 4 

result:

wrong answer Output contains longer sequence [length = 3], but answer contains 2 elements