QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#65316#4584. Not OneSa3tElSefr#TL 957ms112576kbC++201.7kb2022-11-29 19:27:012022-11-29 19:27:03

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:27:03]
  • 评测
  • 测评结果:TL
  • 用时:957ms
  • 内存:112576kb
  • [2022-11-29 19:27:01]
  • 提交

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);
        }
    } else {
        ans = 1;
        for(auto i : g[node]) {
            if(i == par)
                continue;
            ans += dfs(i, node, gcd);
        }
    }
    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;
}

详细

Test #1:

score: 100
Accepted
time: 473ms
memory: 85104kb

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: 509ms
memory: 84148kb

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: 480ms
memory: 84656kb

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: 556ms
memory: 83916kb

input:

2
1 1
1 2

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 814ms
memory: 104932kb

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: 0
Accepted
time: 701ms
memory: 101380kb

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:

70

result:

ok single line: '70'

Test #7:

score: 0
Accepted
time: 785ms
memory: 104632kb

input:

100000
721703 392879 695588 695588 360569 721703 721703 721703 392879 721703 521691 173897 173897 31699 605629 330661 521691 887572 869485 721703 538883 633980 347794 721703 173897 524464 380388 983370 330661 196674 982669 327790 392879 721703 557243 347794 65558 163895 31699 521691 392879 426127 22...

output:

23467

result:

ok single line: '23467'

Test #8:

score: 0
Accepted
time: 806ms
memory: 100404kb

input:

100000
999983 999983 999983 999983 999983 999983 999983 999983 999983 999983 999983 999983 999983 999983 999983 999983 999983 999983 999983 999983 999983 999983 999983 999983 999983 999983 999983 999983 999983 999983 999983 999983 999983 999983 999983 999983 999983 999983 999983 999983 999983 999983...

output:

100000

result:

ok single line: '100000'

Test #9:

score: 0
Accepted
time: 527ms
memory: 91892kb

input:

16666
499521 566687 918452 827210 997739 405921 930466 453499 449367 302663 658220 713125 615536 484783 586258 469620 984395 526320 799319 849099 284114 723734 22671 661826 325985 662335 107207 564634 836931 323058 117954 661326 658962 599495 103335 377185 45338 385027 50770 961843 691799 693591 281...

output:

13

result:

ok single line: '13'

Test #10:

score: 0
Accepted
time: 778ms
memory: 106912kb

input:

66666
10 6 90 60 15 150 90 10 150 12 30 10 12 150 15 50 6 60 60 150 50 50 50 30 10 45 150 6 6 90 50 6 30 12 90 6 60 15 90 45 6 90 45 45 10 60 150 30 30 6 90 12 30 30 6 60 12 45 50 60 45 50 50 50 12 60 10 50 30 150 15 150 90 10 10 12 10 30 6 60 45 6 6 60 12 12 45 12 12 45 12 60 30 30 150 90 6 150 6 6...

output:

46

result:

ok single line: '46'

Test #11:

score: 0
Accepted
time: 577ms
memory: 93220kb

input:

28571
921969 307323 580499 751234 102441 648793 743442 68294 955092 600043 568071 610323 614646 102441 136588 962429 307588 239029 990263 170735 50247 221505 614646 232539 102441 424891 682940 102441 682940 887822 424891 239029 849782 68294 819528 850736 751234 375617 400566 34147 768051 341470 1024...

output:

12698

result:

ok single line: '12698'

Test #12:

score: 0
Accepted
time: 825ms
memory: 111948kb

input:

99415
34616 810608 192350 394543 662841 466264 344614 520619 330891 310932 733902 352703 158039 846731 479629 7807 614728 918662 549561 535798 416048 953051 388610 112163 192506 610550 328203 268293 117567 49639 485945 159856 235364 42325 438801 140386 658755 181970 11852 602321 688908 569920 8816 1...

output:

76

result:

ok single line: '76'

Test #13:

score: 0
Accepted
time: 867ms
memory: 112576kb

input:

100000
280401 761952 441017 796661 314679 435234 485202 937046 696099 625259 759522 701907 631073 602136 209475 52398 548659 494159 499651 614433 138272 622721 61832 606399 466753 468859 572846 371879 766454 93732 607153 230056 390233 203061 609095 889707 266382 543672 616447 159597 211647 597406 14...

output:

11067

result:

ok single line: '11067'

Test #14:

score: 0
Accepted
time: 828ms
memory: 110900kb

input:

93769
849132 451689 130007 436266 701702 236258 740041 423243 934674 413025 770289 426117 465372 974372 315378 228808 858754 236739 725646 533859 789429 269744 152988 160376 426030 801877 82477 507774 383870 776467 894274 928966 699962 309984 294875 605422 9606 445815 776629 262295 735221 617452 411...

output:

46

result:

ok single line: '46'

Test #15:

score: 0
Accepted
time: 483ms
memory: 84016kb

input:

2
1 1024
1 2

output:

1

result:

ok single line: '1'

Test #16:

score: 0
Accepted
time: 957ms
memory: 110164kb

input:

100000
120852 825140 516610 899113 975662 453827 330056 866397 948911 297136 473132 990168 177130 371313 783883 124011 907654 495084 731464 41257 41257 753003 707558 844537 660071 165028 304667 531677 577598 119855 290373 596276 121277 371313 905373 883081 907654 495084 748418 706876 846224 330056 7...

output:

48533

result:

ok single line: '48533'

Test #17:

score: 0
Accepted
time: 911ms
memory: 111780kb

input:

98009
284468 17931 239807 444092 600837 657074 930923 177485 797784 131995 163891 157027 861065 755264 307617 693497 948352 497591 775007 917410 440702 980575 599253 934052 367374 316218 968786 562064 828573 645765 178229 519001 552926 145657 448468 606983 94874 797231 398073 362019 917024 457439 10...

output:

17

result:

ok single line: '17'

Test #18:

score: 0
Accepted
time: 870ms
memory: 110344kb

input:

100000
605131 31849 624816 636980 700678 394807 127396 218640 318490 337430 725037 254792 318490 610305 445886 789614 159245 859923 445886 636980 573282 710019 286641 400445 940163 923621 353112 764376 580433 636980 733213 573282 700678 808165 846015 217463 764376 952758 254792 891772 159245 350339 ...

output:

48014

result:

ok single line: '48014'

Test #19:

score: 0
Accepted
time: 907ms
memory: 110312kb

input:

91139
688753 762129 758881 95826 183968 661949 934118 608838 169928 119627 594829 147490 356787 857384 754661 603417 460695 368970 631753 508848 751838 446058 990793 248660 644624 668725 379802 814955 280476 295208 497117 986965 387186 206451 22867 386355 969750 722994 174613 562047 621884 13385 388...

output:

526

result:

ok single line: '526'

Test #20:

score: 0
Accepted
time: 926ms
memory: 111384kb

input:

100000
944429 816188 148436 823699 335381 851913 295755 78192 690527 253593 43616 399809 446285 341239 103268 557240 760788 831472 415193 681060 848138 687021 192137 34053 968673 737815 751093 805387 419647 449895 707019 18518 278774 367941 613569 56755 363232 113573 691606 545959 556801 836593 7117...

output:

10224

result:

ok single line: '10224'

Test #21:

score: -100
Time Limit Exceeded

input:

92177
434341 827567 843170 499390 493475 462527 706334 578546 626502 698298 942080 520272 227126 488718 647916 917815 15556 983529 763988 309348 887259 735859 120533 555985 269320 253817 512123 754114 656092 177708 616202 348417 231644 972582 92321 786325 985179 608244 948496 772530 271979 298199 30...

output:


result: