QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#305428#4584. Not OneLeeShoW#WA 48ms9436kbC++201.5kb2024-01-15 11:39:522024-01-15 11:39:53

Judging History

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

  • [2024-01-15 11:39:53]
  • 评测
  • 测评结果:WA
  • 用时:48ms
  • 内存:9436kb
  • [2024-01-15 11:39:52]
  • 提交

answer

#include<iostream>
#include<algorithm>
#include<random>
#include<vector>
#include<chrono>
#include<cmath>
#include<queue>
#include<set>
#include<map>
#define pii pair<int,int>
#define int long long
using namespace std;
int all[100005];
int n;
vector<int>v[100005];
vector<int>pr;
vector<pii>edge;
int mx=-1;
int ans=1;
void init(){
    int now=mx;
    for(int i=2;i<=sqrt(now);i++){
        if(now%i==0)pr.push_back(i);
        while(now%i==0){
            now/=i;
        }
    }
    if(now!=1)pr.push_back(now);
}
int f[100005];
int sz[100005];
int find(int x){
    if(x==f[x])return x;
    else return f[x]=find(f[x]);
}
void init1(){
    for(int i=1;i<=n;i++){
        f[i]=i;
        sz[i]=1;
    }
}
signed main(){
    cin>>n;
    int one=0;
    for(int i=1;i<=n;i++){
        cin>>all[i];
        mx=max(mx,all[i]);
        if(all[i]==1)one++;
    }
    init();
    for(int i=0;i<n-1;i++){
        int x,y;
        cin>>x>>y;
        edge.push_back({x,y});
    }
    if(one==n){
        cout<<0<<endl;
        return 0;
    }
    for(auto i:pr){
        init1();
        for(auto [u,v]:edge){
            if(all[u]%i==0&&all[v]%i==0){
                //cout<<i<<" "<<u<<" "<<v<<endl;
                int xx=find(u);
                int yy=find(v);
                //cout<<xx<<" "<<yy<<endl;
                f[xx]=yy;
                sz[yy]+=sz[xx];
                ans=max(sz[yy],ans);
            }
        }
        //cout<<f[2]<<endl;
    }
    cout<<ans<<endl;




    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

4

result:

ok single line: '4'

Test #2:

score: 0
Accepted
time: 1ms
memory: 7648kb

input:

4
1 1 1 1
1 2
2 3
3 4

output:

0

result:

ok single line: '0'

Test #3:

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

input:

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

output:

5

result:

ok single line: '5'

Test #4:

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

input:

2
1 1
1 2

output:

0

result:

ok single line: '0'

Test #5:

score: -100
Wrong Answer
time: 48ms
memory: 9436kb

input:

100000
860163 795323 862289 543383 792647 337047 353985 959953 874318 573652 69827 958063 571741 704399 311826 920477 792478 151531 872269 592307 853819 865817 940735 620657 937154 696551 749279 552523 836161 707467 389626 459089 563763 668884 810391 639709 419361 580342 519595 836124 494959 669379 ...

output:

2

result:

wrong answer 1st lines differ - expected: '213', found: '2'