QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#374486#4686. TourseastcloudWA 1ms4616kbC++141.4kb2024-04-02 14:37:172024-04-02 14:37:18

Judging History

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

  • [2024-04-02 14:37:18]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4616kb
  • [2024-04-02 14:37:17]
  • 提交

answer

#include<bits/stdc++.h>
#define ll unsigned long long
#define N 20005
using namespace std;
ll read(){
    ll x=0,f=1;char ch=getchar();
    while(ch<'0' || ch>'9')f=(ch=='-'?-1:f),ch=getchar();
    while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return x*f;
}
void write(ll x){
    if(x<0)x=-x,putchar('-');
    if(x/10)write(x/10);
    putchar(x%10+'0');
}
vector<ll> e[N],son[N];
mt19937_64 myrand(20080623);
ll dep[N],val[N],f[N];
void dfs(ll x,ll fa){
    f[x]=fa;dep[x]=dep[fa]+1;
    for(auto v:e[x]){
        if(v==fa)continue;
        if(!dep[v])dfs(v,x),son[x].push_back(v);
        else if(dep[v]<dep[x]){
            ll has=myrand();val[x]^=has;if(f[v])val[f[v]]^=has;
        }
    }
    for(auto v:son[x])val[x]^=val[v];
}
ll gcd(ll x,ll y){
    if(!y)return x;
    else return gcd(y,x%y);
}
int main(){
    #ifdef EAST_CLOUD
    freopen("a.in","r",stdin);
    freopen("a.out","w",stdout);
    #endif
    ll n=read(),m=read();
    for(ll i=1;i<=m;i++){
        ll u=read(),v=read();
        e[u].push_back(v);e[v].push_back(u);
    }
    dfs(1,0);
    sort(val+1,val+n+1);ll ans=-1,cnt=1;
    for(ll i=2;i<=n;i++){
        if(val[i]==val[i-1])cnt++;
        else{
            if(ans<0)ans=cnt;
            else ans=gcd(ans,cnt);cnt=1;
        }
    }
    if(cnt)ans=gcd(ans,cnt);
    for(ll i=1;i<=ans;i++)if(ans%i==0)write(i),putchar(' ');
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 1ms
memory: 4616kb

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: 1ms
memory: 4524kb

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: 1ms
memory: 4552kb

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: 1ms
memory: 4564kb

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 

result:

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