QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#91273#2993. 林克卡特树JHN0210 2727ms39152kbC++142.0kb2023-03-28 09:39:002023-03-28 09:39:03

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-28 09:39:03]
  • 评测
  • 测评结果:0
  • 用时:2727ms
  • 内存:39152kb
  • [2023-03-28 09:39:00]
  • 提交

answer

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

typedef double dbl;
typedef long double ld;
typedef long long ll;

const int MAXN=3e5;
const ll INF=1e18;

inline int Read()
{
    int res;char c;
    while(1) {c=getchar();if('0'<=c && c<='9') {res=c-'0';break;}}
    while(1) {c=getchar();if('0'<=c && c<='9') res=res*10+c-'0';else break;}
    return res;
}

int n,K;
struct DE {int nxt,val;};vector<DE> node[MAXN+5];

void DelFa(int now,int fa)
{
    for(vector<DE>::iterator i=node[now].begin();i!=node[now].end();++i)
        if((*i).nxt==fa) {node[now].erase(i);break;}
    for(int i=0;i<node[now].size();i++) DelFa(node[now][i].nxt,now);
}

struct msg {ll f;int g;}dp[MAXN+5][2];//是否有从根向上延伸的链
inline msg Max(msg a,msg b)
{
    if(a.f>b.f) return a;
    if(a.f<b.f) return b;
    if(a.g<b.g) return a;
    return b;
}
inline msg Add(msg a,msg b) {return msg{a.f+b.f,a.g+b.g};}
inline msg Sub(msg a,msg b) {return msg{a.f-b.f,a.g-b.g};}
void Solve(int now,ll v)//每段有个额外代价 v
{
    msg ALL=msg{0,0};
    for(int i=0,rear;i<node[now].size();i++)
    {
        rear=node[now][i].nxt;
        Solve(rear,v),dp[rear][1].f+=node[now][i].val;
        ALL=Add(ALL,dp[rear][0]);
    }
    dp[now][0]=dp[now][1]=ALL;
    msg max1=msg{0,0};
    for(int i=0,rear;i<node[now].size();i++)
    {
        rear=node[now][i].nxt;
        msg now1=Sub(dp[rear][1],dp[rear][0]);
        dp[now][0]=Max(dp[now][0],Add(Add(ALL,Add(max1,now1)),msg{-v,1}));
        max1=Max(max1,now1);
        dp[now][1]=Max(dp[now][1],Add(ALL,max1));
    }
}

int main()
{
    n=Read(),K=Read();
    for(int i=1,a,b,c;i<n;i++)
    {
        a=Read(),b=Read(),c=Read();
        node[a].push_back(DE{b,c});
        node[b].push_back(DE{a,c});
    }
    DelFa(1,0);
    ll L=-3e11,R=3e11;
    for(ll mid;L<=R;)
    {
        mid=L+((R-L)>>1);
        Solve(1,mid);
        if(dp[1][0].g<=K+1) R=mid-1;
        else L=mid+1;
    }
    Solve(1,L);
    printf("%lld\n",dp[1][0].f+dp[1][0].g*L);
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1559ms
memory: 27904kb

input:

200000 0
65350 50045 831081
197523 52910 450640
102223 58430 595075
145187 41777 -548397
119538 69164 -976961
42852 63503 -590523
155411 169713 -523260
156688 13869 -63012
199944 82780 21461
93164 20930 -202990
2189 180064 931389
89237 187565 277289
156421 46988 774727
29142 19573 -953773
44537 1258...

output:

16595848221

result:

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

Test #2:

score: 0
Wrong Answer
time: 2648ms
memory: 36960kb

input:

300000 0
197640 17080 162783
269725 187014 -181947
240689 261756 129022
226971 264281 338196
2415 179116 -871598
103266 44170 -454670
63425 143632 660611
205510 137031 -575054
248763 191913 233536
106763 213425 369236
197546 277600 -933947
219363 134954 807154
156605 218354 -516243
23354 181485 -803...

output:

33596292864

result:

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

Test #3:

score: 0
Wrong Answer
time: 1454ms
memory: 27884kb

input:

200000 1
181791 162820 711757
127748 11452 -795032
80860 71793 525612
195881 135260 -126472
183820 157817 665318
165220 20364 400920
187386 108213 -236737
133696 28527 280508
26024 19170 59816
18044 95464 497705
96297 191435 -191786
130752 20531 -683234
94787 31667 441623
47892 175810 -734631
146477...

output:

4947973171

result:

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

Test #4:

score: 0
Wrong Answer
time: 2515ms
memory: 34912kb

input:

300000 1
188256 180568 -883916
297662 188433 62579
72882 3060 802792
173772 156239 -685924
89475 97850 109283
189977 238977 668196
147681 137368 287673
130735 126820 328423
163022 197254 404113
103379 245688 273971
84409 142542 121838
279404 107017 349027
53002 42234 150702
38970 130301 -657900
2262...

output:

21708785144

result:

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

Test #5:

score: 0
Wrong Answer
time: 1499ms
memory: 26808kb

input:

200000 2
169901 12952 -717273
167468 57457 57238
112530 187631 720251
140886 80961 -211382
169996 116263 747467
133399 190844 -317325
37450 39059 -649790
189065 39630 28609
123082 110715 -212169
27668 161879 -8632
192678 126317 566068
15559 23831 -820002
147769 67130 -565425
96285 77276 11875
137112...

output:

19929246019

result:

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

Test #6:

score: 0
Wrong Answer
time: 1336ms
memory: 28992kb

input:

200000 2
12078 169076 -942765
44175 99956 231323
133198 8579 171890
18545 179563 -85659
99402 116954 -31337
31702 166261 441837
31558 170873 531500
176395 135683 124560
161927 102775 -976865
35809 136934 299229
191169 34738 -533879
185462 176939 -750013
43633 41368 -926589
71922 149691 -137419
13463...

output:

8454169426

result:

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

Test #7:

score: 0
Wrong Answer
time: 2675ms
memory: 36624kb

input:

300000 2
220743 272654 5034
119645 261362 707980
258300 182256 -670779
182916 190543 -319978
153462 244137 -863595
249563 134557 -982616
223363 22292 61412
47052 11723 -305744
91646 202184 -303558
272326 24578 -647471
48668 168529 233438
30267 295657 -410001
213986 81526 -386001
276522 87775 969181
...

output:

34584840809

result:

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

Test #8:

score: 0
Wrong Answer
time: 1525ms
memory: 27356kb

input:

200000 100
16537 61788 402424
161077 77028 -919110
117310 153524 -290999
183518 111544 -117636
73244 165828 883254
117689 166229 -406860
102026 40518 78656
159440 72889 -675522
106123 23028 732235
86129 134361 340255
56567 159088 58610
125473 59177 -372900
158520 163684 -349257
108476 165042 875739
...

output:

21996714147

result:

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

Test #9:

score: 0
Wrong Answer
time: 1440ms
memory: 29496kb

input:

200000 100
159645 190327 -790296
181809 12423 601994
123183 83267 -49442
134128 130575 -143436
164650 149794 429016
47721 105379 296109
18240 27184 762687
38772 128862 596455
113039 3632 -307682
158647 61354 301670
63054 125621 -331135
12548 92826 570965
189760 87332 500426
74656 19969 228158
131009...

output:

20992612940

result:

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

Test #10:

score: 0
Wrong Answer
time: 2557ms
memory: 33780kb

input:

300000 100
131574 241226 825936
43551 161469 -432167
92729 242024 -852728
201397 89958 -598808
212544 177234 33151
160560 166450 857
270273 200219 -436713
287533 21869 -586096
206427 267598 48749
151663 185902 -336130
124834 57033 -435251
14650 115941 564478
240297 64983 714036
56725 256596 574766
9...

output:

22888448668

result:

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

Test #11:

score: 0
Wrong Answer
time: 2265ms
memory: 36496kb

input:

300000 100
263059 214437 -956970
266221 5485 -984258
181157 191851 337012
166949 93678 423724
270903 216008 -533514
178527 242172 63569
190242 167484 -620162
74008 278321 -654753
170660 3765 353481
181023 8801 982726
155475 162086 -824228
237659 285329 799133
222437 90885 822446
144544 187010 88694
...

output:

26434633955

result:

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

Test #12:

score: 0
Wrong Answer
time: 2253ms
memory: 34824kb

input:

300000 100
25419 209149 -500631
108405 59781 442111
293496 81726 -921827
135966 256780 -174547
209773 193974 -358614
21666 114744 -106858
221058 70979 -209083
295305 246008 -585729
148509 157116 -640851
143114 200242 651047
75896 68199 -893175
297649 209143 422060
213992 183699 199818
201195 275824 ...

output:

21770899876

result:

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

Test #13:

score: 0
Wrong Answer
time: 1448ms
memory: 29744kb

input:

200000 130406
40594 19720 -623122
23706 44660 -874727
198946 155951 446918
18573 173446 -730875
620 170942 760623
90071 160815 -451054
44927 119046 601497
152317 43323 547496
13277 66904 -129002
39821 13557 -337519
97682 195872 473610
135525 112760 -323544
191848 22168 950602
25024 195672 -479997
98...

output:

59891932703

result:

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

Test #14:

score: 0
Wrong Answer
time: 1257ms
memory: 28360kb

input:

200000 112025
19434 26866 -522901
41544 82125 340019
42503 188348 -283235
47014 76883 -752315
192433 97139 -364401
142520 45516 773937
119246 43968 -87291
24207 146679 868137
80687 82213 -813080
36329 84717 -568093
122342 155905 -124629
166598 28449 925294
36746 7420 -767398
186177 79549 -558811
123...

output:

59907395520

result:

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

Test #15:

score: 0
Wrong Answer
time: 1523ms
memory: 27956kb

input:

200000 159073
90997 155660 688588
122016 194855 364001
108373 157814 921909
126532 153527 89711
77452 13721 434419
168396 14935 -742122
25592 91528 -156210
171969 92303 830841
174160 64741 993375
90321 26349 -426120
108013 164044 720212
150049 110076 525431
172048 119753 887134
145459 147158 78386
1...

output:

59969482210

result:

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

Test #16:

score: 0
Wrong Answer
time: 1383ms
memory: 26032kb

input:

200000 138730
34756 87461 -636823
118637 99255 -915828
126441 146865 191707
142168 127467 -20126
81775 88255 -222870
165937 84373 716993
104552 144925 -279669
157496 176688 691692
91940 55387 996047
26473 100735 402521
180263 64826 -845891
193409 27113 -260656
82076 68265 -505721
47211 61310 330882
...

output:

60196876554

result:

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

Test #17:

score: 0
Wrong Answer
time: 2183ms
memory: 33460kb

input:

300000 129178
23041 100501 -373992
227874 165730 605092
67462 240962 -713691
109035 104054 -362417
187831 102896 554829
335 127284 -810036
141401 282130 750195
228816 71494 -696039
130283 15637 771038
119508 43490 520169
42895 277561 504582
103769 114888 -343346
73436 73051 491763
196506 25657 13280...

output:

89768435347

result:

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

Test #18:

score: 0
Wrong Answer
time: 2727ms
memory: 39152kb

input:

300000 152830
264154 103322 476154
41997 134920 -402116
163045 84775 591957
109208 9792 -983414
23856 44103 -745743
90231 82597 -569317
170372 74011 -945586
90507 199076 -328824
134113 2043 -636000
240437 131789 555722
236029 167549 -799563
273537 278524 287973
7746 84943 707424
113967 107808 -81031...

output:

89285265117

result:

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

Test #19:

score: 0
Wrong Answer
time: 2679ms
memory: 34972kb

input:

300000 220606
73646 165467 211934
287560 202214 503555
133070 247406 930057
135894 259547 953228
71803 157101 -918434
222521 210059 -833619
207233 164303 424927
28849 254325 -553475
115615 159949 44857
71463 13068 -109967
220595 75134 902520
266060 244008 632129
288006 100470 602933
150032 239332 53...

output:

89367446173

result:

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

Test #20:

score: 0
Wrong Answer
time: 2302ms
memory: 32284kb

input:

300000 177288
96606 159646 -843008
6102 77679 -290722
162415 126260 610363
143376 146328 -745143
64929 265269 605571
183004 109222 754682
59516 295312 -675501
17670 184822 740404
203705 225595 -824744
249255 59274 761581
299854 210063 -551417
231581 65698 808182
181562 142802 143491
146718 135568 -2...

output:

90021886501

result:

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