QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#873642#10038. Centrifugerotcar07AC ✓88ms32568kbC++141.3kb2025-01-26 19:21:392025-01-26 19:21:40

Judging History

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

  • [2025-01-26 19:21:40]
  • 评测
  • 测评结果:AC
  • 用时:88ms
  • 内存:32568kb
  • [2025-01-26 19:21:39]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
constexpr int N=2e5+5,mod=998244353;
int n,a[N];
vector<int> e[N];
int dp[N],sz[N],inv[N],deg[N],sb[N];
inline void red(int&x){x>=mod&&(x-=mod);}
void dfs(int p,int f){
    sz[p]=1;deg[p]=e[p].size();sb[p]=inv[max(deg[p]-1,1)];
    for(int x:e[p])if(x!=f){
        dfs(x,p);
        sz[p]+=sz[x];
        red(dp[p]+=dp[x]);
    }
    dp[p]=(dp[p]+a[p]*1ll*(sz[p]-1))%mod*sb[p]%mod;
    dp[p]=(dp[p]+a[p]*1ll*inv[deg[p]])%mod;
    // cout<<p<<' '<<dp[p]<<'\n';
}
void dfss(int p,int f){
    // cout<<p<<' '<<dp[p]<<'\n';
    for(int x:e[p])if(x!=f){
        dp[x]=(dp[x]+(dp[p]-dp[x]*1ll*inv[max(deg[p]-1,1)]%mod-a[p]*1ll*sz[x]%mod*sb[p]%mod)*sb[x]%mod+mod+a[x]*1ll*(n-sz[x])%mod*sb[x]%mod)%mod;
        dfss(x,p);
    }
}
int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i],a[i]%=mod;
    if(n==1){
        cout<<a[1]<<'\n';
        return 0;
    }
    for(int i=1,u,v;i<n;i++) cin>>u>>v,e[u].emplace_back(v),e[v].emplace_back(u);
    inv[1]=1;
    for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*1ll*inv[mod%i]%mod;
    for(int i=1;i<=n;i++) a[i]=a[i]*1ll*inv[n]%mod;
    dfs(1,0);
    dfss(1,0);
    for(int i=1;i<=n;i++) cout<<(deg[i]==1?(dp[i]+mod-a[i])%mod:0)<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 12004kb

input:

3
1 2 4
1 2
2 3

output:

3
0
4

result:

ok 3 number(s): "3 0 4"

Test #2:

score: 0
Accepted
time: 1ms
memory: 11836kb

input:

6
4 1 3 11 7 2
1 4
2 3
6 2
2 4
4 5

output:

928921837
0
818005794
0
679360751
568444705

result:

ok 6 numbers

Test #3:

score: 0
Accepted
time: 1ms
memory: 10180kb

input:

1
41

output:

41

result:

ok 1 number(s): "41"

Test #4:

score: 0
Accepted
time: 1ms
memory: 10436kb

input:

2
2 0
2 1

output:

1
1

result:

ok 2 number(s): "1 1"

Test #5:

score: 0
Accepted
time: 0ms
memory: 10964kb

input:

3
5 3 10
1 2
1 3

output:

0
831870302
166374069

result:

ok 3 number(s): "0 831870302 166374069"

Test #6:

score: 0
Accepted
time: 1ms
memory: 11896kb

input:

4
0 2 8 10
4 2
3 4
1 3

output:

748683274
249561099
0
0

result:

ok 4 number(s): "748683274 249561099 0 0"

Test #7:

score: 0
Accepted
time: 1ms
memory: 11876kb

input:

5
2 3 3 2 6
1 3
4 2
3 5
4 3

output:

698771051
199648876
0
0
99824442

result:

ok 5 number(s): "698771051 199648876 0 0 99824442"

Test #8:

score: 0
Accepted
time: 0ms
memory: 11876kb

input:

6
5 2 7 3 1 2
4 2
6 5
1 2
5 2
5 3

output:

97051540
0
277290105
596173715
0
27729013

result:

ok 6 numbers

Test #9:

score: 0
Accepted
time: 0ms
memory: 12388kb

input:

7
4 8 2 6 1 9 1
4 6
4 7
3 1
5 1
1 2
4 2

output:

0
0
332748124
0
118838619
629844664
915057330

result:

ok 7 numbers

Test #10:

score: 0
Accepted
time: 1ms
memory: 11092kb

input:

8
3 10 7 10 0 6 0 1
4 7
5 3
2 1
3 8
7 8
7 1
1 6

output:

0
904658956
0
686293003
249561096
155975688
0
0

result:

ok 8 numbers

Test #11:

score: 0
Accepted
time: 0ms
memory: 10308kb

input:

9
6 5 2 3 0 3 0 10 9
4 6
3 5
3 7
9 2
4 2
2 1
3 1
8 3

output:

0
0
0
0
496041178
952029346
496041178
237237095
813384300

result:

ok 9 numbers

Test #12:

score: 0
Accepted
time: 0ms
memory: 10936kb

input:

10
8 6 2 6 2 7 8 10 1 8
10 2
6 9
9 5
7 2
2 8
5 8
1 5
3 5
3 4

output:

865145116
0
0
266198504
0
133099257
865145120
0
0
865145120

result:

ok 10 numbers

Test #13:

score: 0
Accepted
time: 1ms
memory: 10496kb

input:

23
171012762 382302936 224526965 498682874 623846655 397366638 365412109 279133137 537092512 784206006 850876801 256245089 166123203 413296787 323459300 118280143 422543076 208223509 304304551 167965007 245457682 976636968 248293370
7 3
20 11
23 19
10 18
21 17
12 1
1 17
3 17
3 16
22 14
14 20
2 6
4 5...

output:

0
0
0
0
66636257
135626452
592053067
0
801197085
180292910
546335948
911670690
709269029
0
0
0
0
0
0
0
322469992
851654308
853349283

result:

ok 23 numbers

Test #14:

score: 0
Accepted
time: 0ms
memory: 11120kb

input:

104
802315532 576558287 904092257 614188021 856428595 511535224 634364555 821943919 240433262 997802100 736344532 920010384 799273884 725136407 184126589 263698636 915023304 668233384 186736194 816057802 60702330 671673040 332551983 693613385 227517544 518203296 578072626 708593858 511852932 6671171...

output:

0
0
0
5277544
0
0
0
0
920646502
235645813
0
732452907
0
0
711350218
0
779426865
0
688212218
762546888
170377974
0
0
0
890455760
0
0
0
0
360147814
801073396
690219108
0
0
540586146
0
0
0
869588495
0
0
423557135
0
0
0
47275123
0
0
664535038
0
168098738
0
0
498981050
17729480
0
755307218
0
0
0
0
0
0
0
...

result:

ok 104 numbers

Test #15:

score: 0
Accepted
time: 0ms
memory: 10676kb

input:

231
725789836 140974074 494273058 518434096 365253512 545194531 110823467 860518524 685199849 419806059 440591488 957490476 596024209 685078744 634204830 381863834 613351724 310582050 602272449 392368382 635774253 576227491 565020559 526475973 320179250 326758826 974429584 872334003 156501934 162220...

output:

0
0
0
0
708964127
445536840
0
0
984106443
0
0
0
0
0
0
629938568
971001636
723340233
0
0
616928789
0
0
480694509
0
0
264987635
535172137
0
0
819842753
84170022
53910636
533370910
0
0
0
0
0
0
270125238
736744510
0
475460103
510190845
0
0
703266270
0
437595507
0
0
0
323826193
779502439
0
0
548827694
71...

result:

ok 231 numbers

Test #16:

score: 0
Accepted
time: 2ms
memory: 12024kb

input:

6022
308507152 439071175 404161839 681343292 698436539 150097487 525982538 103253313 319482558 651662051 445998504 380015231 804213919 717549652 173020857 674925113 219855976 122369630 651522335 833870206 942352839 667565344 560078161 661413098 474658628 789350422 223635769 657445717 531181044 85752...

output:

0
0
0
0
0
0
558706793
0
202548517
119643535
890512184
202260279
0
0
199735098
0
0
0
0
797335313
519239766
0
442582784
0
0
0
164845852
0
0
691051485
26150518
0
926223941
0
0
0
963433821
0
0
0
0
0
996902046
0
0
0
312902156
0
0
140075113
0
776371994
660224224
746102573
0
406885994
0
568420639
0
0
0
302...

result:

ok 6022 numbers

Test #17:

score: 0
Accepted
time: 2ms
memory: 12196kb

input:

13333
764338851 521446334 72616562 520422075 429815786 389682344 535400391 322947919 757454608 903972982 380609534 930243608 606849875 253457028 383710039 212498230 843823865 568342476 840108508 456380567 405938364 521845472 946576887 926729626 410883571 374312620 634497545 168566128 988615253 77300...

output:

0
145966787
218484243
463529962
0
0
0
983721351
905987371
0
0
142182732
0
420160779
0
0
0
0
486557257
0
360719554
796801474
212497384
539879108
0
96474110
0
0
0
783018146
0
0
377375253
0
0
762979428
616592435
117832594
129637794
968627421
0
479102729
709629517
0
187816065
894956226
0
0
0
364071989
4...

result:

ok 13333 numbers

Test #18:

score: 0
Accepted
time: 32ms
memory: 14732kb

input:

78243
20308083 907490417 328226499 637943457 916820109 318607845 129990667 178538062 294339724 986165024 593857812 875711527 403376412 477902019 576769903 785106250 790500557 572433192 860877970 445014424 187192014 467861814 755609992 600470776 273200850 304018454 310917633 394231134 173972649 15796...

output:

0
488511668
641075813
0
0
33617788
0
0
0
0
0
0
0
0
0
0
0
0
0
0
281545307
0
0
349337882
0
0
0
106587544
0
0
0
539415184
0
0
0
866426622
0
0
162461003
0
496238789
608259155
207969167
0
0
453581042
0
0
0
405481294
0
557454533
0
0
0
871252666
0
0
0
0
674772528
0
0
0
0
330512538
56789869
0
0
0
0
0
152035...

result:

ok 78243 numbers

Test #19:

score: 0
Accepted
time: 37ms
memory: 15048kb

input:

100001
391217412 137907436 294092007 95486636 522460732 780670053 550281151 207926284 634004932 251318871 136041281 540425316 297626403 277347156 83890900 124885718 937743997 980740064 45128225 750453314 424157695 322722939 77371070 613585736 33331352 595548571 174150987 97759515 217776349 444652962...

output:

0
0
0
0
0
0
0
0
226374144
0
854086135
0
0
0
0
701261627
0
0
777576994
0
221756730
0
733620591
0
0
613803201
311864531
0
0
33003410
382786041
0
619553264
0
92923396
0
0
949093645
668051487
0
0
0
0
0
0
441596287
278550854
0
982021847
824733802
0
0
0
0
281966609
0
644164972
0
0
0
0
0
0
464485867
0
0
0
...

result:

ok 100001 numbers

Test #20:

score: 0
Accepted
time: 88ms
memory: 19040kb

input:

189123
492941328 642273822 28114711 247389009 541608434 397507866 764862033 51804161 220279977 225527125 369516229 556461930 431653716 142611435 769932207 330954407 277918140 362419044 561298474 285505848 739635904 422605381 89854169 110933350 430280435 979229908 443190254 191227301 61370376 7005595...

output:

88044221
0
0
0
0
0
0
0
133232667
927372497
280403539
0
563301707
0
0
0
0
0
0
0
95700482
0
0
224253697
507724562
0
128158146
0
961425760
0
726800803
853164200
0
0
0
0
148927996
288304637
0
0
0
455170934
0
0
0
640071876
840529931
0
169264339
0
0
0
0
0
33779540
609127558
0
454266907
0
0
0
0
0
0
0
55070...

result:

ok 189123 numbers

Test #21:

score: 0
Accepted
time: 74ms
memory: 19376kb

input:

195321
135012673 718701628 310510612 229642887 341847217 509611721 561554064 630834923 469897421 335060493 963270761 118079310 155177006 508752673 614256349 494934264 830059223 731575877 568814740 648712615 66087968 370703097 250358235 762472608 921448259 908976231 869205979 894805004 576277554 1305...

output:

0
0
0
0
732665626
250762764
0
0
0
912716203
762664300
968127640
987019945
0
0
366998831
0
0
0
0
0
0
0
547700547
651065339
0
779976154
0
0
0
0
486615367
0
0
144681148
796805635
0
0
0
0
927067048
0
0
129523768
0
0
185510162
282674124
0
0
0
214190065
126110822
0
50063738
577287037
0
835434352
0
0
0
0
0...

result:

ok 195321 numbers

Test #22:

score: 0
Accepted
time: 88ms
memory: 19316kb

input:

200000
322266659 113147721 247745686 240259530 635935210 490162229 299933303 621882492 605316960 635674424 913736711 680549857 695916480 162996883 640251852 488682813 509829838 561895326 650278300 959803039 258612915 37570425 567402274 209804457 799280638 985509611 252472980 686214114 155702256 8427...

output:

0
697213896
0
0
0
0
315333111
0
0
562338679
0
0
0
428484464
0
0
0
0
722877702
75073523
0
0
0
191075020
247413729
935033670
797902690
0
0
0
0
0
638817267
0
0
640979588
0
447398201
0
0
0
223743420
0
842744224
0
0
341494172
733496920
0
0
0
0
0
877177559
0
0
0
861310388
55576076
912101970
0
41981840
554...

result:

ok 200000 numbers

Test #23:

score: 0
Accepted
time: 73ms
memory: 31492kb

input:

199234
158550882 666697470 600428767 986702943 742981937 728558971 571026013 265919530 504814117 645766686 148102156 892943251 669089765 723385394 310717994 648418125 710295419 713509215 269533567 628851099 489509167 45302040 25109015 373015117 53441254 796038143 10726367 976680709 287935249 8003693...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 199234 numbers

Test #24:

score: 0
Accepted
time: 76ms
memory: 24144kb

input:

197321
906855832 773488995 233156506 607805629 637216495 129262753 914327202 644424853 935195091 944762452 9490292 876933386 578025304 80363252 194621662 616070940 763164863 682659492 354559086 325323873 287571100 49789746 168915374 939497760 848674704 498934299 992381792 933859910 385398127 3517706...

output:

622262054
0
0
767503058
0
0
480859899
0
832253510
470591432
778136851
0
0
0
0
0
0
0
695937460
0
0
0
527364087
776238416
0
595596278
0
885880912
254778771
5163506
832096943
879308085
186052228
431203857
574848467
201188934
366651105
930599361
732998692
487821361
700452172
722525941
0
0
951574466
0
34...

result:

ok 197321 numbers

Test #25:

score: 0
Accepted
time: 65ms
memory: 18828kb

input:

189243
322778722 532604939 192799272 503177363 643074897 367208169 768284015 898617698 420054278 493661809 912357779 294825948 511808698 230914458 560976477 467945169 395228333 295911589 201491758 597356768 960429466 846491318 467634740 480719550 657579235 663886091 312921838 658354285 234141236 477...

output:

0
0
0
0
558786258
847171050
0
0
0
0
0
0
0
0
0
562745525
740934458
72399866
231021538
399076538
966760684
0
612890676
0
0
505806527
0
767699087
982500424
0
0
83673698
808293549
881611550
0
140858349
0
0
0
925642189
0
0
209745323
850509889
352223388
0
491087857
185746659
0
293390202
154846070
0
0
4697...

result:

ok 189243 numbers

Test #26:

score: 0
Accepted
time: 66ms
memory: 26248kb

input:

189243
268551314 699240681 484945435 664009706 808537232 164440819 526976343 772107871 390615176 115109510 547198503 622312562 524958823 514878412 924558768 719541768 874432796 458960049 369764183 102479168 136241132 639682797 164174165 386746020 456509086 124854620 810126188 993451880 69757711 2339...

output:

613987260
239547057
0
0
0
500510961
450013762
390022655
0
0
95087198
842639502
971089579
789461589
915905970
0
151132682
133929646
513232459
0
286107071
833073734
0
0
0
335359752
334164139
0
870867913
825592194
212516628
0
0
0
623382262
0
0
973687104
0
0
0
758628669
0
0
0
340810978
742615531
0
17394...

result:

ok 189243 numbers

Test #27:

score: 0
Accepted
time: 78ms
memory: 32568kb

input:

200000
174075341 890735572 609783385 653074034 644371975 682008123 35040998 154048031 247229453 829290836 150692148 516828283 970350591 314104463 292894841 527123478 731391279 307150861 652782209 817235813 383459824 455936554 474325985 692550108 996886456 845370309 285213196 322716801 885797437 2944...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 200000 numbers

Test #28:

score: 0
Accepted
time: 82ms
memory: 26068kb

input:

200000
872997226 652621624 71639505 22997759 978841632 557166981 317745816 17693733 553160283 271013245 95695506 915724933 697792638 817169622 320714261 244784810 866713138 175877785 199972072 553088236 566304730 596190310 736506571 704014654 643344615 737065903 366500443 282013108 828244798 7465591...

output:

64987609
373548168
0
555965144
968030458
585530732
0
0
0
0
0
587336637
0
756682617
0
0
474136337
0
0
0
493454719
0
0
348155897
0
567882729
0
729899873
774405139
0
0
783702680
0
750924677
405135203
948273435
0
0
792505975
621055572
915771785
626703191
0
734241287
262855482
193334733
953598120
0
58816...

result:

ok 200000 numbers

Test #29:

score: 0
Accepted
time: 67ms
memory: 19160kb

input:

200000
604575871 240660691 47413566 388848055 668976092 919371503 567376983 209766301 28745479 687798650 70262115 694348074 545766493 411143969 337228955 197355371 428285675 561370739 23634410 887070026 959262525 773999505 364122218 904765181 172466919 376730938 473475400 69196288 711012311 31911954...

output:

0
87714615
472893116
0
93024613
686762373
186091484
558822786
659537427
584564867
910690362
0
559408236
0
311785227
351748278
0
0
0
426358590
0
588593528
0
0
495192062
331436359
0
0
0
399857620
275547434
0
0
0
0
305847579
329455172
981077705
290969335
953945901
341196886
0
0
0
0
898468954
457936589
...

result:

ok 200000 numbers

Test #30:

score: 0
Accepted
time: 76ms
memory: 26760kb

input:

200000
259467035 862508252 544062500 275872716 193400465 208050450 510897480 2669863 553812183 360718601 844644579 745791969 236750388 277764941 9835926 314306945 823291698 934798157 760965858 385542634 944752202 388744731 254902655 892468183 925209342 441221363 937072355 227816424 598205771 9882561...

output:

0
511313501
518434669
658252934
513010978
444448226
349735916
0
0
917289541
0
0
0
0
0
896793032
0
0
743358489
995305627
0
902845435
0
0
716029437
195055249
0
476187521
0
532009929
283456517
918224005
240586326
0
0
0
939462284
0
800357927
0
36783637
368619362
0
0
327124233
89536361
0
0
0
951095991
0
...

result:

ok 200000 numbers

Test #31:

score: 0
Accepted
time: 78ms
memory: 29808kb

input:

200000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 200000 numbers

Test #32:

score: 0
Accepted
time: 1ms
memory: 9800kb

input:

1
998244353

output:

0

result:

ok 1 number(s): "0"

Test #33:

score: 0
Accepted
time: 0ms
memory: 8776kb

input:

1
998244352

output:

998244352

result:

ok 1 number(s): "998244352"

Test #34:

score: 0
Accepted
time: 1ms
memory: 9804kb

input:

1
998244354

output:

1

result:

ok 1 number(s): "1"

Test #35:

score: 0
Accepted
time: 0ms
memory: 9928kb

input:

1
1000000000

output:

1755647

result:

ok 1 number(s): "1755647"