QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#225642#4584. Not OneAbtahi#WA 261ms114724kbC++142.0kb2023-10-24 21:56:242023-10-24 21:56:25

Judging History

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

  • [2023-10-24 21:56:25]
  • 评测
  • 测评结果:WA
  • 用时:261ms
  • 内存:114724kb
  • [2023-10-24 21:56:24]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef unordered_map<int,int> umap;
typedef long double ld;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define popcount __builtin_popcount
#define case cout<<"Case "<<__testcase-testcase<<": ";


vector<bool> yes;
vector<vii> g;
int cnt=0;
void dfs(int u){
    if(yes[u]) return;
    yes[u]=true;
    cnt++;
    for(auto v: g[u]) dfs(v);
    return;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int testcase=1;
    //cin>>testcase;
    int __testcase=testcase;
    while(testcase--){
        int n,m,i,j,k;
        cin>>n;
        yes.assign(n+5, false);
        g.resize(n+5);
        vii a(n+1); for(i=1;i<=n;i++) cin>>a[i];
        const int N=1000005;
        vii p[N];
        for(i=2;i<N;i++){
            if(p[i].size()) continue;
            for(j=i;j<N;j+=i) p[j].pb(i);
        }
        vii node[N];
        vector<vii> edge[N];
        for(i=1;i<=n;i++){
            if(a[i]==1) continue;
            for(auto j: p[i]) node[j].pb(i);
        }
        //cout<<"done"<<endl;
        for(i=0;i<n-1;i++){
            int u,v;
            cin>>u>>v;
            for(auto j: p[a[u]]){
                if(find(p[a[v]].begin(), p[a[v]].end(), j)==p[a[v]].end()) continue;
                edge[j].pb({u,v});
            }
        }
        //cout<<"done"<<endl;
        int ans=0;
        for(i=2;i<N;i++){
            if(p[i].size()>1) continue;
            //cout<<i<<endl;
            for(auto e: edge[i]){
                g[e[0]].pb(e[1]);
                g[e[1]].pb(e[0]);
            }
            for(auto j: node[i]) yes[j]=false;
            for(auto j: node[i]){
                if(yes[j]) continue;
                cnt=0;
                dfs(j);
                ans=max(ans, cnt);
            }
        }
        cout<<ans<<endl;
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 208ms
memory: 105708kb

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: 213ms
memory: 105744kb

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: 199ms
memory: 105700kb

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: 199ms
memory: 105704kb

input:

2
1 1
1 2

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 261ms
memory: 114724kb

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:

213

result:

ok single line: '213'

Test #6:

score: -100
Wrong Answer
time: 234ms
memory: 112924kb

input:

100000
999983 999983 999961 999961 999979 999979 999979 999961 999983 999961 999979 999961 999961 999983 999961 999983 999983 999979 999961 999979 999983 999979 999983 999961 999979 999961 999979 999979 999961 999979 999983 999979 999961 999961 999961 999961 999961 999983 999979 999983 999979 999961...

output:

1

result:

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