QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#305431#4584. Not OneLeeShoW#TL 1ms7576kbC++201.7kb2024-01-15 12:00:352024-01-15 12:00:36

Judging History

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

  • [2024-01-15 12:00:36]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:7576kb
  • [2024-01-15 12:00:35]
  • 提交

answer

#include<iostream>
#include<algorithm>
#include<random>
#include<vector>
#include<chrono>
#include<cmath>
#include<queue>
#include<set>
#include<map>
#include<cstring>
#define pii pair<int,int>
using namespace std;
int all[100005];
int n;
vector<int>v[100005];
vector<int>pr;
vector<pii>edge;
int mx=-1;
int ans=1;
bool is[1000005];
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;
    set<int>st;
    set<int>prr;
    for(int i=1;i<=n;i++){
        cin>>all[i];
        mx=max(mx,all[i]);
        st.insert(all[i]);
        if(all[i]==1)one++;
    }
    for(auto i:st){
        int now=i;
        vector<int>alll;
        for(int i=2;i<=sqrt(now);i++){
            if(now%i==0)alll.push_back(i);
            while(now%i==0){
                now/=i;
            }
        }
        if(now!=1)
        alll.push_back(now);
        for(auto owo:alll){
            prr.insert(owo);
        }
    }
    for(auto i:prr){
        pr.push_back(i);
    }
    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();
        //cerr<<i<<endl;
        for(auto [u,v]:edge){
            if(all[u]%i==0&&all[v]%i==0){
                int xx=find(u);
                int yy=find(v);
                f[xx]=yy;
                sz[yy]+=sz[xx];
                ans=max(sz[yy],ans);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

详细

Test #1:

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

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

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

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

input:

2
1 1
1 2

output:

0

result:

ok single line: '0'

Test #5:

score: -100
Time Limit Exceeded

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:


result: