QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#789082 | #4686. Tours | b6e0 | WA | 0ms | 3948kb | C++14 | 580b | 2024-11-27 19:14:06 | 2024-11-27 19:14:09 |
Judging History
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;
}
详细
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