QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#65315#4584. Not OneSa3tElSefr#WA 960ms105376kbC++201.5kb2022-11-29 19:18:272022-11-29 19:18:29

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-29 19:18:29]
  • 评测
  • 测评结果:WA
  • 用时:960ms
  • 内存:105376kb
  • [2022-11-29 19:18:27]
  • 提交

answer

#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double


const int N = 1e6 + 1, mod = 1e9 + 7;
int n, a[N];
bool prime[N];
vector<int> d[N], g[N];
map<pair<int, int>, int> dp;
int dfs(int node, int par, int gcd) {
    if(gcd != N && a[node] % gcd)
        return dp[{node, gcd}] = 0;
    if(dp.count({node, gcd}))
        return dp[{node, gcd}];
    int &ans = dp[{node, gcd}];
    if(gcd == N) {
        for(auto i : g[node]) {
            if(i == par)
                continue;
            ans = max(ans, dfs(i, node, N));
        }
    }
    for(auto j : d[a[node]]) {
        int cnt = 1;
        for(auto i : g[node]) {
            if(i == par)
                continue;
            cnt += dfs(i, node, j);
        }
        ans = max(ans, cnt);
    }
    return ans;
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    memset(prime, true, sizeof prime);
    for(int i = 2;i < N;i++) {
        if(!prime[i])
            continue;
        for(int j = i;j < N;j += i) {
            prime[j] = false;
            d[j].push_back(i);
        }
    }
    cin >> n;
    for(int i = 1;i <= n;i++)
        cin >> a[i];
    for(int i = 1;i < n;i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    cout << dfs(1, 1, N);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 542ms
memory: 84684kb

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: 563ms
memory: 84344kb

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: 580ms
memory: 83748kb

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: 548ms
memory: 84016kb

input:

2
1 1
1 2

output:

0

result:

ok single line: '0'

Test #5:

score: -100
Wrong Answer
time: 960ms
memory: 105376kb

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:

293

result:

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