QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#305432 | #4584. Not One | LeeShoW# | TL | 2ms | 11748kb | C++20 | 1.7kb | 2024-01-15 12:03:21 | 2024-01-15 12:03:21 |
Judging History
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 num[1000005];
void init(){
int now=mx;
memset(is,0,sizeof(is));
for(int i=2;i<=now;i++){
if(is[i]==1)continue;
bool yes=0;
for(int j=i+i;j<=now;j+=i){
if(num[j]){
yes=1;
}
is[j]=1;
}
if(yes)pr.push_back(i);
}
}
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;
memset(num,0,sizeof(num));
for(int i=1;i<=n;i++){
cin>>all[i];
num[all[i]]=1;
mx=max(mx,all[i]);
st.insert(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();
//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: 2ms
memory: 11748kb
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: 2ms
memory: 10792kb
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: 2ms
memory: 10812kb
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: 2ms
memory: 10808kb
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 ...