QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#730261#6782. 快餐店qwertim100 ✓1553ms27516kbC++202.4kb2024-11-09 19:28:382024-11-09 19:28:38

Judging History

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

  • [2024-11-09 19:28:38]
  • 评测
  • 测评结果:100
  • 用时:1553ms
  • 内存:27516kb
  • [2024-11-09 19:28:38]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define i128 __int128
#define ull unsigned long long
#define int long long
#define fo(i,l,r) for(int i=l;i<=r;i++)
#define fd(i,r,l) for(int i=r;i>=l;i--)
#define sqrt __builtin_sqrt
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pdd pair<double,double>
#define tiii tuple<int,int,int>
#define fi first
#define se second
#define mem(a,b) memset(a,b,sizeof a)
inline int read(){char c=getchar();int a=0,b=1;while(c<'0'||c>'9')b=(c=='-'?-1:b),c=getchar();while(c>='0'&&c<='9')a=a*10+(c^48),c=getchar();return a*b;}inline void write(int x){if(x<0)putchar('-'),x=-x;if(x>9)write(x/10);putchar(x%10+'0');}template<typename T>void cmax(T&x,T y){x=max(x,y);}template<typename T>void cmin(T&x,T y){x=min(x,y);}
int n,x,y,L,w[500005],f[500005],ans,maxn,tmp;
int a[500005],b[500005],c[500005],d[500005];
bool flag;
bitset<500005>vis;
vector<pii>v[500005];
int S[500005],sk[500005],Top,top;
void find_r(int x,int fa){
	if(flag)return;
	if(vis[x]){
		while(S[Top]^x)sk[++top]=S[Top--];
		sk[++top]=S[Top--],flag=1;
		return;
	}
	vis[x]=1,S[++Top]=x;
	for(auto[i,j]:v[x])if(i^fa){
		find_r(i,x);
		if(flag)return;
	}
	Top--;
}
void initf(int x,int fa,int dis){
	if(maxn<dis)maxn=dis,tmp=x;
	for(auto[i,j]:v[x])if(i^fa)initf(i,x,dis+j);
}
void initg(int x,int fa,int no1,int no2,int dis){
	cmax(ans,dis);
	for(auto[i,j]:v[x])if(i^fa&&i^no1&&i^no2)initg(i,x,no1,no2,dis+j);
}
int work(int x){
	int dis=0,st=0;
    // fo(i,1,top)cerr<<sk[i]<<' ';
	// cerr<<'\n';
	fo(i,1,top)dis+=w[i-1],a[i]=max(a[i-1],dis+f[sk[i]]),b[i]=max(b[i-1],st+dis+f[sk[i]]),cmax(st,f[sk[i]]-dis);//cerr<<a[i]<<' '<<b[i]<<'\n';;
	dis=st=0;
	fd(i,top,1)dis+=(i<top)*w[i],c[i]=max(c[i+1],dis+f[sk[i]]),d[i]=max(d[i+1],st+dis+f[sk[i]]),cmax(st,f[sk[i]]-dis);//cerr<<c[i]<<' '<<d[i]<<' '<<dis<<'\n';
	int anst=b[top];
	fo(i,2,top)cmin(anst,max({b[i-1],d[i],a[i-1]+w[top]+c[i]}));
	return max(ans,anst);
}
signed main(){
	ios::sync_with_stdio(0);
	// freopen("foodshop.in","r",stdin);
	cin>>n;
	fo(i,1,n)cin>>x>>y>>L,v[x].push_back({y,L}),v[y].push_back({x,L});
	find_r(1,0);
	fo(i,1,top){
		int l=sk[i-1?i-1:top],r=sk[i>=top?1:i+1];
		for(auto[j,k]:v[sk[i]])
			if(j==r)w[i]=k;
			else if(j^l){
				maxn=tmp=0;
				initf(j,sk[i],0),cmax(f[sk[i]],maxn+k);
				initg(tmp,0,l,r,0);
			}
	}
	cout<<fixed<<setprecision(1)<<1.*work(sk[1])/2;
	return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 5
Accepted
time: 2ms
memory: 10088kb

input:

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

output:

3.5

result:

ok "3.5"

Test #2:

score: 5
Accepted
time: 2ms
memory: 9964kb

input:

80
79 78 1
54 57 1
53 56 1
71 70 1
19 21 1
35 32 1
70 68 1
8 6 1
65 63 1
7 10 1
36 34 1
64 66 1
15 17 1
12 14 1
76 77 1
16 15 1
45 44 1
73 71 1
17 19 1
53 51 1
64 63 1
36 38 1
32 29 1
24 23 1
27 24 1
70 72 1
8 9 1
78 75 1
60 58 1
58 61 1
5 4 1
69 66 1
27 28 1
65 68 1
22 20 1
4 1 1
20 18 1
50 48 1
72...

output:

19.5

result:

ok "19.5"

Test #3:

score: 5
Accepted
time: 0ms
memory: 10136kb

input:

300
246 244 90
79 78 55
260 262 9
172 171 94
5 4 55
100 103 14
21 18 93
6 8 61
54 52 64
180 182 56
250 247 64
126 129 57
54 55 68
229 226 27
230 228 48
86 83 100
202 200 24
72 73 6
200 198 85
20 19 24
115 112 26
271 274 49
185 187 89
122 124 18
19 22 77
23 26 3
18 19 5
51 49 87
111 108 74
157 158 5
...

output:

3789.0

result:

ok "3789.0"

Test #4:

score: 5
Accepted
time: 2ms
memory: 10060kb

input:

400
360 364 83
264 267 15
1 3 77
275 271 41
252 249 19
179 182 99
284 281 28
62 58 97
8 9 19
100 96 11
124 122 11
388 390 50
95 98 3
11 14 72
74 73 63
378 375 4
47 43 62
279 276 14
19 16 83
20 19 49
178 177 57
167 164 86
254 257 86
147 149 64
304 300 31
380 376 92
57 59 84
24 21 7
255 259 32
189 190...

output:

3828.0

result:

ok "3828.0"

Test #5:

score: 5
Accepted
time: 2ms
memory: 8136kb

input:

600
190 189 65
221 222 39
290 289 97
470 469 46
534 533 23
336 337 37
142 141 86
119 118 65
209 210 65
298 299 21
442 443 63
11 12 79
571 570 32
5 4 81
343 342 31
105 106 35
314 313 77
425 424 87
596 597 57
273 274 20
21 20 38
13 14 38
232 231 58
594 595 2
507 506 5
521 522 18
551 550 86
117 116 24
...

output:

14705.0

result:

ok "14705.0"

Test #6:

score: 5
Accepted
time: 2ms
memory: 10140kb

input:

600
251 253 43
316 315 53
156 154 24
559 557 76
283 281 59
275 273 73
348 350 62
373 370 6
401 398 76
7 10 90
126 129 16
213 215 52
395 393 78
28 27 21
112 115 81
406 409 70
112 111 93
1 3 27
299 302 33
58 59 45
339 341 92
22 21 47
113 116 44
290 292 27
418 417 11
22 23 2
21 18 57
598 599 53
313 311...

output:

7325.5

result:

ok "7325.5"

Test #7:

score: 5
Accepted
time: 2ms
memory: 10128kb

input:

1000
92 95 534882222
860 856 692066046
117 120 977972434
506 510 759247345
894 891 260734605
384 388 334815034
494 490 528576171
93 90 151974447
286 282 114816838
229 226 12015825
288 284 263317144
598 593 131119174
10 13 436239629
171 170 718124937
15 11 30893980
662 660 188770912
602 599 654741592...

output:

77823371904.5

result:

ok "77823371904.5"

Test #8:

score: 5
Accepted
time: 0ms
memory: 10208kb

input:

1500
939 938 536654812
118 116 556063346
391 388 21579666
701 700 695151306
1278 1277 767716875
1062 1064 249763933
7 5 102024010
803 802 929079421
1401 1400 493533536
1163 1161 3842249
11 10 855658229
869 870 341402203
674 677 156472356
394 391 217933123
457 460 486011276
455 452 790659124
1432 142...

output:

166291447069.5

result:

ok "166291447069.5"

Test #9:

score: 5
Accepted
time: 5ms
memory: 10084kb

input:

1700
506 908 337695675
1 2 758392132
1020 845 18669664
17 1 907268663
840 1327 824335893
1196 1316 659872014
674 1068 645136884
1047 367 167240151
636 1 863951781
1250 522 531047843
857 433 41392596
5 154 168432276
1484 764 752954082
18 1 465008183
1598 1666 268596699
617 1352 348430868
1050 1339 30...

output:

4101206269.5

result:

ok "4101206269.5"

Test #10:

score: 5
Accepted
time: 2ms
memory: 10244kb

input:

1800
1314 1319 574444787
935 929 125284730
1210 1201 807712963
1 4 604191201
273 275 69920794
1798 1796 15301194
1422 1412 385233438
200 199 316142137
116 110 803832460
1 10 874273894
1063 1064 303588359
7 12 153707446
568 560 349437104
1304 1303 766944361
700 696 165820662
1278 1274 478367125
550 5...

output:

74650554378.0

result:

ok "74650554378.0"

Test #11:

score: 5
Accepted
time: 0ms
memory: 10328kb

input:

2000
108 110 227780278
1302 1304 364146029
1604 1607 305987508
353 354 585703747
1269 1267 318550382
4 6 857478803
1120 1121 778271252
389 390 414023975
454 456 61264116
1706 1704 886137054
540 539 140768238
925 928 190749367
1962 1965 184641832
857 856 675555371
1228 1225 330483971
1668 1670 412700...

output:

233042889330.0

result:

ok "233042889330.0"

Test #12:

score: 5
Accepted
time: 2ms
memory: 10176kb

input:

2000
1189 1423 222173594
113 416 834398444
429 1 581724132
199 1 253595901
1296 1017 875118772
1801 1629 174806859
472 497 128054667
65 1 432641162
910 1198 196311240
37 11 580141863
1049 978 551433850
1427 1582 471613126
363 193 576155507
592 979 789452783
1 15 276482718
534 810 57790468
1692 1248 ...

output:

6850958567.0

result:

ok "6850958567.0"

Test #13:

score: 5
Accepted
time: 183ms
memory: 11548kb

input:

20000
5751 6175 177337070
1658 2408 145616989
6192 7038 532020536
18127 17344 447422755
9398 8416 328918730
3461 3367 872989661
4472 3479 960544178
8878 8747 530192424
18137 17901 275187846
17761 16849 736490601
11 1 857556217
13388 13268 357062915
1 13 552940715
1 14 985056205
18445 18423 701918278...

output:

23771653877.5

result:

ok "23771653877.5"

Test #14:

score: 5
Accepted
time: 14ms
memory: 13624kb

input:

40000
11866 11873 882630511
36821 36814 78997572
29004 29003 916427234
11573 11570 5470217
4 5 21436961
19290 19301 275044415
34482 34473 63069943
25655 25664 455094061
23184 23172 545155844
8 10 125713298
11 1 404870927
13147 13136 465251732
20028 20034 35231902
18386 18397 74976249
3214 3202 40933...

output:

1441400129321.5

result:

ok "1441400129321.5"

Test #15:

score: 5
Accepted
time: 19ms
memory: 18904kb

input:

70000
47214 47212 886251792
2 1 5194938
66081 66075 15639715
50763 50758 240768150
18773 18766 613507473
67467 67462 184066049
3915 3921 903310528
49064 49065 202914087
26540 26541 258686145
16617 16621 503554384
9 11 516318282
23591 23597 257179898
31171 31173 118771942
11766 11772 987773995
36633 ...

output:

4088181242477.5

result:

ok "4088181242477.5"

Test #16:

score: 5
Accepted
time: 567ms
memory: 16508kb

input:

80000
26250 26561 588638957
2875 2323 565107355
30989 31412 177405683
1 4 861481900
31548 30975 847276400
12539 11920 396654336
74832 75561 771924129
73347 73505 530483146
14716 14918 569705836
29209 29144 20715850
19839 19610 547310904
1 12 177774915
16416 15702 218349058
1 14 466790574
1896 1637 6...

output:

103080362877.5

result:

ok "103080362877.5"

Test #17:

score: 5
Accepted
time: 1553ms
memory: 17764kb

input:

100000
35281 34331 207197716
49810 50143 313796281
54856 55188 31898806
44107 43585 66834672
5 1 132053090
94715 94248 476122216
29270 29659 67621507
65663 65611 195659537
1 9 513706688
55802 56797 147206360
1 11 963140745
13782 14049 292867545
21390 21299 13203696
47954 47139 746780880
13081 13711 ...

output:

102694837576.0

result:

ok "102694837576.0"

Test #18:

score: 5
Accepted
time: 35ms
memory: 25656kb

input:

100000
35380 35378 568127154
3691 3693 89109899
32235 32237 15832622
59428 59430 751818092
4 5 109640371
12636 12635 964823452
78281 78283 517117640
72976 72974 717651183
74624 74626 714388741
91906 91905 274705630
9978 9976 58816454
82112 82110 5146330
63612 63610 81224999
38133 38132 98978784
2220...

output:

15565095383581.5

result:

ok "15565095383581.5"

Test #19:

score: 5
Accepted
time: 45ms
memory: 27516kb

input:

100000
50157 50156 868102375
31097 31096 125062615
43322 43321 395179599
93473 93472 672146199
5 4 47583662
23849 23848 119017381
7 6 933156810
71745 71746 390579627
58307 58308 67099709
91786 91787 463594151
66521 66520 268634755
6475 6476 70853401
74193 74192 520896338
14823 14824 792058494
93977 ...

output:

23437055346823.0

result:

ok "23437055346823.0"

Test #20:

score: 5
Accepted
time: 681ms
memory: 16180kb

input:

80000
64135 64506 370447826
70376 70196 354480701
2427 2862 430466701
5822 6256 774398736
76570 75871 568638326
1 6 595077704
39068 38888 432588821
60245 59910 81131224
1 9 506306273
34310 33636 952282669
11 1 612158564
9822 10487 102299212
79471 79932 794395187
54338 54302 494057704
62271 61749 456...

output:

106897087111.0

result:

ok "106897087111.0"

Extra Test:

score: 0
Extra Test Passed