QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#466511#5092. 森林游戏D_F_S100 ✓66ms35072kbC++14904b2024-07-07 21:26:502024-07-07 21:26:51

Judging History

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

  • [2024-07-07 21:26:51]
  • 评测
  • 测评结果:100
  • 用时:66ms
  • 内存:35072kb
  • [2024-07-07 21:26:50]
  • 提交

answer

#include<bits/stdc++.h>
#include<bits/extc++.h>
#define inl inline
using namespace std;
typedef long long ll;
const int N=2e5+5,IB=1<<21; char IN[IB],*IS=IN+IB,*IT=IS;
#define gc() (IS==IT&&(IT=IN+fread(IS=IN,1,IB,stdin)),IS==IT?EOF:*IS++)
int n,a[N]; ll an; vector<int> e[N]; __gnu_pbds::priority_queue<ll> q[N];
inl int RD()
{
	int s=0; char c; for(;!isdigit(c=gc()););
	for(;isdigit(c);c=gc()) s=s*10+c-48; return s;
}
inl void DFS(int p,int fr)
{
	for(int v:e[p]) v!=fr&&(DFS(v,p),q[p].join(q[v]),0); ll t=a[p],v=1;
	for(;!q[p].empty()&&(v<1||t<q[p].top());t-=v*q[p].top(),q[p].pop(),v*=-1);
	v<1?(an+=(n&1?-1:1)*t):(q[p].push(t),0);
}
int main()
{
	n=RD(); for(int i=1;i<=n;++i) an+=a[i]=RD();
	for(int x,y,i=n;--i;e[x=RD()].push_back(y=RD()),e[y].push_back(x));
	DFS(1,0); ll v=1; for(;!q[1].empty();an+=v*q[1].top(),q[1].pop(),v*=-1);
	printf("%lld\n",an/2); return 0;
}

詳細信息

Subtask #1:

score: 20
Accepted

Test #1:

score: 20
Accepted
time: 0ms
memory: 14044kb

input:

20
530933472 920863930 136179483 46535289 291417568 338674057 731327836 375973098 986104110 203163644 489326483 785212564 712578139 801609721 666347686 282530991 823910542 217884304 785578553 116701831
8 3
18 19
11 20
2 18
8 13
5 15
12 16
7 8
10 9
13 6
17 10
17 18
13 15
18 4
13 12
1 14
17 15
15 14
5...

output:

4611098449

result:

ok 1 number(s): "4611098449"

Test #2:

score: 0
Accepted
time: 3ms
memory: 14560kb

input:

20
384529189 217795442 901954855 742992564 354875060 497288585 40376145 575315239 263212445 574630916 520470316 917128880 461333242 407666839 565926566 390970156 568486150 291329847 493439854 637783217
10 17
19 8
20 17
7 17
9 6
17 14
16 18
4 3
9 14
6 2
14 18
13 4
11 15
9 3
7 12
16 1
8 14
5 14
9 15

output:

4410782058

result:

ok 1 number(s): "4410782058"

Test #3:

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

input:

19
601996737 696498327 385657564 527861058 529330573 376647612 223077352 338754937 682264670 671903443 645156487 755321105 978945836 120368247 611275923 947566064 98892994 858404931 401419272
11 14
8 14
3 6
13 12
16 15
1 4
11 4
2 7
4 3
15 5
2 1
13 5
10 16
9 16
1 17
18 6
3 19
5 7

output:

5848746543

result:

ok 1 number(s): "5848746543"

Subtask #2:

score: 20
Accepted

Dependency #1:

100%
Accepted

Test #4:

score: 20
Accepted
time: 3ms
memory: 14156kb

input:

1000
379354617 199235046 102686848 841958378 178689385 896777301 798019293 538540178 877449071 825184825 426375184 882476194 614078703 438824267 731949932 770345838 655572525 687098129 758287148 690715403 984914877 365231609 752380073 509777049 511312331 889780846 745450511 740863321 552773286 15071...

output:

252915929540

result:

ok 1 number(s): "252915929540"

Test #5:

score: 0
Accepted
time: 3ms
memory: 14352kb

input:

999
402468827 468124822 806603931 945584323 480102625 19722 169790452 515757998 19958108 528988204 415841643 111279190 885615782 740479752 550815713 556065700 511850711 148616044 552183365 471481958 946651162 968386282 610171866 971986310 377716133 564442897 222395758 16053401 613716892 487668831 48...

output:

249829986618

result:

ok 1 number(s): "249829986618"

Test #6:

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

input:

1000
637313417 62510663 83128345 702987667 374713776 778401168 619811617 896369345 486498325 448824176 297332011 916674955 895413407 803990450 21693588 866905388 169932411 340234047 259184127 331450756 506720779 194809709 896076578 936050255 925430496 741889050 638981221 628789074 358540287 89791215...

output:

226446817254

result:

ok 1 number(s): "226446817254"

Test #7:

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

input:

1000
147397255 520346638 619331018 431963137 427476094 995854324 640680706 473132459 1061281 701469953 87766202 316181634 506906587 181791922 174614534 639267313 489608085 693127159 412762229 906080005 562083964 319379642 148511208 32431198 908725162 531631359 390987308 965197199 851576914 95327968 ...

output:

229874635771

result:

ok 1 number(s): "229874635771"

Test #8:

score: 0
Accepted
time: 3ms
memory: 14380kb

input:

999
98690497 488296773 570509174 87593828 566189245 345232397 309963286 886305731 195509167 561473976 304758565 239428403 9228891 38443063 343536428 606219587 806177708 94853421 426729965 393545389 820769556 365126116 489908193 276668395 217091957 976510596 415255517 670037302 793997764 947495706 10...

output:

266569042607

result:

ok 1 number(s): "266569042607"

Subtask #3:

score: 20
Accepted

Test #9:

score: 20
Accepted
time: 51ms
memory: 35060kb

input:

200000
999987004 602156102 91769712 379660190 720439584 919049125 100899098 730818653 388815487 42718845 476924022 19840101 257503361 516286381 512038918 41148716 852674011 622135181 27036209 735194423 704085603 913120290 932441023 385347390 594902535 381944419 994681925 585953160 720457154 92452005...

output:

49989866089917

result:

ok 1 number(s): "49989866089917"

Test #10:

score: 0
Accepted
time: 48ms
memory: 31604kb

input:

199999
999999704 934248941 346628737 218143040 35171165 242481543 101821655 603144433 370500506 320500244 523438923 329477462 506219498 691354348 176837694 924202225 152540255 518279760 856769521 846590282 988631361 343152840 678925659 274564441 928488734 548653238 639582264 563780193 311970659 2372...

output:

49995048269713

result:

ok 1 number(s): "49995048269713"

Test #11:

score: 0
Accepted
time: 52ms
memory: 31680kb

input:

200000
999989614 458317092 235142909 301368380 667650190 387357601 942552018 462322286 665746330 301926861 257583236 109820676 903369129 759393758 322144226 46484299 478746477 419210844 715104421 714731594 482372962 902259953 817692958 220576793 402290769 654706387 83324492 83088723 935798259 340549...

output:

49997998711742

result:

ok 1 number(s): "49997998711742"

Test #12:

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

input:

199999
999994869 113685391 536055361 208275322 834508272 382926623 433638309 742578812 270668940 444050243 981890271 997484410 185408871 103885877 104431880 845910297 615511524 850229327 541022585 254158786 196594114 61519522 59714548 734071969 920629543 468465539 94897735 650806012 905929055 223489...

output:

49964042377264

result:

ok 1 number(s): "49964042377264"

Subtask #4:

score: 20
Accepted

Test #13:

score: 20
Accepted
time: 38ms
memory: 22544kb

input:

200000
730100868 442913942 39803860 967290083 690169489 381641013 900703306 20889915 950398724 118310294 935844438 932217907 511925207 26490266 546668120 251512807 45167784 984574524 225892728 28349344 771174130 218513912 465021609 181656143 904495544 478771443 410959812 45087984 596651521 862715225...

output:

46109137394335

result:

ok 1 number(s): "46109137394335"

Test #14:

score: 0
Accepted
time: 44ms
memory: 22476kb

input:

200000
558029416 297545430 634869443 249447306 471440671 251383009 4233616 670802768 633913365 579181472 266082501 461294758 681042610 702241946 9858502 790529308 855718320 339148188 223139799 227618010 929746535 555844464 413612226 790105597 980428607 44735263 351953615 738684004 714267051 70786106...

output:

46052340414870

result:

ok 1 number(s): "46052340414870"

Test #15:

score: 0
Accepted
time: 39ms
memory: 22524kb

input:

199999
960679460 159339164 16690576 678258674 181179172 852303517 758541900 935064939 482744308 660679396 12050636 447520289 25002219 809150682 15621142 155481520 473243823 10879593 537052158 306169734 75832152 892873359 14668548 340176146 291977204 832796528 957414504 738981007 950323533 429195484 ...

output:

53857533309625

result:

ok 1 number(s): "53857533309625"

Test #16:

score: 0
Accepted
time: 36ms
memory: 22496kb

input:

199999
464198406 302405151 358105012 851493619 50546219 236948165 850259964 946052133 399507611 831340592 713461572 419057457 14508381 222376154 473750538 762767542 395467474 285450057 799301679 964545373 414062130 596271603 386876226 237061911 440081578 601815857 842484410 227099995 551936506 88796...

output:

53727755479948

result:

ok 1 number(s): "53727755479948"

Subtask #5:

score: 20
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Test #17:

score: 20
Accepted
time: 38ms
memory: 35040kb

input:

200000
690165079 323521125 91099941 864409953 258730979 230387432 432784897 907886395 803136640 924444422 18406681 789192131 91699645 488884692 418867667 247391798 42162196 572955805 824935383 155542923 197084708 919386447 16915473 46161616 965420801 8361995 391063084 393998063 229316378 157770858 8...

output:

50100473472834

result:

ok 1 number(s): "50100473472834"

Test #18:

score: 0
Accepted
time: 40ms
memory: 35072kb

input:

199999
758655540 672309767 727187333 294208394 135059038 95644812 714942272 754430280 80070564 421721945 730178756 483394477 939073396 997287191 691460267 989127870 755016107 289357188 124240958 404388120 178890102 287875715 605576485 281099928 75142321 70698355 28536363 544030117 725213197 97125240...

output:

49912006041002

result:

ok 1 number(s): "49912006041002"

Test #19:

score: 0
Accepted
time: 35ms
memory: 24128kb

input:

200000
926976936 321873757 999178959 569010694 433641583 111368136 298897045 416675743 446772433 50535169 408123145 937593607 481190479 556944315 867718605 238150318 693941852 151189722 265721354 597408399 914337165 313809361 46239277 706998169 435703626 732935404 286027452 976499611 235306646 55674...

output:

50049916738084

result:

ok 1 number(s): "50049916738084"

Test #20:

score: 0
Accepted
time: 47ms
memory: 26108kb

input:

199999
357743230 104658314 629093318 648353264 307954376 56198420 398971540 428310041 46063855 49695656 726245468 346918529 685301818 284755978 862779077 314638775 946777096 691068711 205523420 77117044 342788516 147043615 274186947 16157300 100222564 553092281 702121504 750971589 650914120 17480982...

output:

50012768089567

result:

ok 1 number(s): "50012768089567"

Test #21:

score: 0
Accepted
time: 52ms
memory: 25084kb

input:

200000
114200933 515473038 127443409 307922107 389547646 979218369 520725415 712389075 933826751 732514784 806020550 163326092 427942453 757906659 891606287 809363300 133133235 876997150 79971625 222079719 963533745 13304001 20593313 771469953 842991010 475849587 369605950 338561826 990634063 827852...

output:

48152420522100

result:

ok 1 number(s): "48152420522100"

Test #22:

score: 0
Accepted
time: 43ms
memory: 22520kb

input:

199999
305267194 827882224 868509831 608008775 912172683 419786250 166566034 649311597 840325182 499875972 359955831 437753991 42412320 976644917 927753661 786222427 945746276 922294352 789646705 717398657 926776452 488296105 355042426 255896524 817201409 700588522 895292391 595552373 390262937 3169...

output:

52066756920875

result:

ok 1 number(s): "52066756920875"