QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#874507#9687. 仙人掌染色JohnAlfnov#30 77ms35012kbC++14921b2025-01-28 09:41:562025-01-28 09:41:56

Judging History

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

  • [2025-01-28 09:41:56]
  • 评测
  • 测评结果:30
  • 用时:77ms
  • 内存:35012kb
  • [2025-01-28 09:41:56]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,m,p;
vector<pair<int,int>>g[200005];
long long f0[200005],f1[200005];
void dfs0(int x,int la,int c2){
	int d=0;
	long long ff=0;
	vector<long long>vc;
	for(auto pi:g[x]){
		++d;int cu=pi.first,cc=pi.second;
		if(cu==la)continue;
		dfs0(cu,x,cc);ff+=f0[cu];
		vc.emplace_back(f1[cu]-f0[cu]);
	}
	sort(vc.begin(),vc.end(),greater<long long>());
	f0[x]=ff;f1[x]=ff+1ll*d*(d-1)*p-c2;
	int sz=vc.size();
	__int128 he=0;
	for(int i=0;i<sz;++i){
		he+=vc[i];
		f0[x]=max((__int128)f0[x],he+1ll*(i+1)*(d-i-1)*d*p+ff);
		if(la)f1[x]=max((__int128)f1[x],he-c2+1ll*(i+2)*(d-i-2)*d*p+ff);
	}
}
int main(){
	scanf("%d%d%d",&n,&m,&p);
	for(int i=1;i<=m;++i){
		int u,v,w;
		scanf("%d%d%d",&u,&v,&w);w*=2;
		g[u].emplace_back(v,w);
		g[v].emplace_back(u,w);
	}
	if(m==n-1){
		dfs0(1,0,0);
		printf("%lld\n",f0[1]/2);
		return 0;
	}
	return 0;
}

詳細信息

Subtask #1:

score: 7
Accepted

Test #1:

score: 7
Accepted
time: 1ms
memory: 10956kb

input:

20 19 444
1 2 932
2 3 9129
1 4 3180
4 5 502
4 6 3906
4 7 4020
4 8 2771
2 9 4132
6 10 3311
2 11 1547
3 12 7576
11 13 1254
6 14 1653
7 15 6855
6 16 8691
5 17 2048
3 18 8097
12 19 2113
10 20 2594
0 0
1 0
2 0
1 1
2 3
2 4
2 5
2 6
2 1
3 4
2 2
3 0
3 2
3 5
3 7
3 6
3 3
3 1
4 0
4 1

output:

7569

result:

ok answer is '7569'

Test #2:

score: 7
Accepted
time: 0ms
memory: 10056kb

input:

20 19 570
1 2 10
1 3 3
3 4 4
3 5 4
4 6 7
2 7 2
5 8 0
7 9 10
2 10 1
2 11 5
1 12 6
2 13 4
10 14 10
2 15 9
8 16 9
8 17 9
8 18 9
4 19 8
19 20 3
0 0
1 0
1 1
2 5
2 6
3 2
2 0
3 4
3 0
2 1
2 2
1 2
2 3
3 1
2 4
4 1
4 2
4 3
3 3
4 0

output:

27334

result:

ok answer is '27334'

Test #3:

score: 7
Accepted
time: 0ms
memory: 11580kb

input:

20 19 389
1 2 6358
2 3 6342
3 4 5165
4 5 3974
5 6 9030
1 7 7437
1 8 2856
1 9 8098
1 10 7327
1 11 9108
1 12 1742
1 13 1336
1 14 9080
1 15 501
1 16 5086
1 17 1331
1 18 3535
1 19 8930
1 20 4691
0 0
1 0
2 0
3 0
4 0
5 0
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14

output:

147388

result:

ok answer is '147388'

Test #4:

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

input:

20 19 996
1 2 6343
2 3 4327
3 4 7056
4 5 8316
5 6 6511
1 7 3194
1 8 9784
1 9 239
1 10 6493
1 11 7645
1 12 1188
1 13 3829
1 14 4949
1 15 4056
1 16 7516
1 17 2020
10 18 1299
1 19 2256
1 20 4835
0 0
1 0
2 0
3 0
4 0
5 0
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
2 1
1 12
1 13

output:

324846

result:

ok answer is '324846'

Subtask #2:

score: 0
Wrong Answer

Dependency #1:

100%
Accepted

Test #5:

score: 0
Wrong Answer
time: 0ms
memory: 10056kb

input:

15 20 265
13 15 0
5 14 4
15 10 8
3 12 9
14 7 0
7 11 2
5 9 1
5 13 0
6 5 5
13 2 8
2 3 7
2 12 2
14 9 2
14 1 1
1 8 5
13 10 0
6 2 9
14 4 10
11 4 2
14 8 9
4754354 3960467
4629204 2001500
6793471 6167134
2135231 397939
4054633 471608
8818077 1222890
4313744 8937757
3700257 7400078
9056146 3171567
1832451 2...

output:


result:

wrong output format Unexpected end of file - token expected

Subtask #3:

score: 3
Accepted

Dependency #1:

100%
Accepted

Test #11:

score: 3
Accepted
time: 2ms
memory: 10056kb

input:

5000 4999 610
1 2 1965
2 3 4777
2 4 5957
2 5 8820
4 6 6213
5 7 109
7 8 6335
8 9 3
7 10 3715
10 11 474
7 12 4698
6 13 4799
8 14 2979
9 15 8005
9 16 6216
5 17 3682
4 18 4635
2 19 1259
5 20 962
1 21 401
14 22 4103
20 23 8509
11 24 6237
9 25 8202
8 26 8866
7 27 8539
20 28 2811
23 29 8060
1 30 8008
28 31...

output:

4272781564

result:

ok answer is '4272781564'

Test #12:

score: 3
Accepted
time: 2ms
memory: 11444kb

input:

8000 7999 105
1 2 1704
1 3 6950
1 4 1836
1 5 1002
1 6 7226
1 7 9243
1 8 7298
1 9 1999
1 10 680
1 11 6175
1 12 3669
1 13 1104
1 14 6543
1 15 8914
1 16 812
1 17 6525
1 18 4551
1 19 342
1 20 4837
1 21 8167
1 22 8301
12 23 5584
1 24 1174
1 25 7824
1 26 9762
1 27 5679
1 28 5521
1 29 8448
1 30 2357
1 31 6...

output:

3819876223392

result:

ok answer is '3819876223392'

Test #13:

score: 3
Accepted
time: 2ms
memory: 11340kb

input:

8000 7999 352
1 2 1793
2 3 2096
3 4 9372
4 5 9802
5 6 9226
6 7 1130
7 8 6785
8 9 9112
9 10 8026
10 11 783
11 12 5532
12 13 1630
13 14 5805
14 15 9619
15 16 8787
16 17 6733
17 18 2522
18 19 36
19 20 2066
20 21 6159
21 22 6721
22 23 8138
23 24 8130
24 25 4329
25 26 8347
26 27 4709
27 28 6817
28 29 558...

output:

4890413099933

result:

ok answer is '4890413099933'

Subtask #4:

score: 9
Accepted

Dependency #3:

100%
Accepted

Test #14:

score: 9
Accepted
time: 2ms
memory: 10824kb

input:

6560 6559 936
612 1661 141
1556 2672 9935
3186 5498 7334
1556 3791 1141
1556 5274 5148
1556 4382 9947
1556 5507 9448
5254 1814 3560
1556 1802 3957
4149 5350 6290
1556 1870 2470
1556 5725 2102
1556 5344 615
1556 1804 2131
1556 2139 9177
1556 878 556
1556 4769 4378
1556 6445 8551
1556 1353 7057
1556 3...

output:

19465870192297

result:

ok answer is '19465870192297'

Test #15:

score: 9
Accepted
time: 4ms
memory: 10696kb

input:

8000 7999 524
872 2240 7746
2571 290 1333
1495 4963 9262
1027 6592 7241
3333 1615 4056
2067 6621 636
2895 1816 6643
2320 2170 3902
4125 3674 9822
6357 5016 7934
3393 3151 2928
6632 6297 8223
6026 7454 7955
7849 2308 9893
4063 5453 7576
4092 1203 8485
2942 977 6593
5235 1397 8843
4686 5085 3267
7909 ...

output:

420867

result:

ok answer is '420867'

Test #16:

score: 9
Accepted
time: 2ms
memory: 11592kb

input:

8000 7999 712
462 2947 4370
4261 6499 8722
1231 7075 1931
750 2079 5922
2074 5286 2102
7594 5184 5703
2087 1857 5705
2009 1146 2521
7962 7555 7332
1261 1159 8774
7119 501 6059
7154 586 6065
1138 2437 4761
4934 7339 5023
2401 2384 7223
3296 6537 477
7270 6489 2176
3800 7210 3917
87 7248 1371
2957 653...

output:

726620

result:

ok answer is '726620'

Subtask #5:

score: 0
Skipped

Dependency #2:

0%

Subtask #6:

score: 11
Accepted

Dependency #4:

100%
Accepted

Test #31:

score: 11
Accepted
time: 61ms
memory: 19276kb

input:

200000 199999 591
1 2 712
1 3 3028
1 4 56
1 5 3878
4 6 9579
1 7 5054
4 8 303
6 9 4293
3 10 3097
9 11 3270
5 12 8292
4 13 5894
3 14 6645
11 15 7422
13 16 5419
1 17 7723
16 18 2775
13 19 7612
1 20 1965
14 21 6314
11 22 9871
3 23 3851
11 24 87
16 25 7976
11 26 9026
25 27 8732
8 28 4290
3 29 6025
8 30 5...

output:

54095245642

result:

ok answer is '54095245642'

Test #32:

score: 11
Accepted
time: 71ms
memory: 27500kb

input:

200000 199999 554
190009 179065 2540
190009 129514 3604
190009 184746 3212
73130 173024 3805
172448 165256 259
190009 139039 8045
190009 103385 4620
190009 82590 7279
190009 97738 2112
176322 176196 1307
190009 171773 1986
190009 150419 8155
127496 104121 5747
190009 155055 1704
190009 193935 6483
2...

output:

119801666217302465

result:

ok answer is '119801666217302465'

Test #33:

score: 11
Accepted
time: 55ms
memory: 23876kb

input:

200000 199999 782
193263 184209 9212
193263 97605 4495
37805 111317 4726
193263 124662 2505
193263 137624 2361
193263 163616 1049
193263 137563 9114
193263 177282 4739
193263 118232 863
193263 155556 38
91415 110509 7395
193263 139108 9667
193263 124764 6145
193263 159739 6316
193263 95381 1620
1932...

output:

453111308894148624

result:

ok answer is '453111308894148624'

Test #34:

score: 11
Accepted
time: 77ms
memory: 35012kb

input:

200000 199999 124
37389 170116 0
84762 83853 2
164451 156923 0
12015 115579 3
140993 189249 0
33471 6703 2
172772 168392 3
93631 130796 0
60476 170854 2
143609 120586 0
165805 55922 3
100861 137821 0
136333 134554 1
71742 55776 0
174292 186448 1
178309 171483 3
113633 89445 0
120048 110244 0
84200 1...

output:

24650782

result:

ok answer is '24650782'

Subtask #7:

score: 0
Wrong Answer

Test #35:

score: 0
Wrong Answer
time: 44ms
memory: 16080kb

input:

175359 200000 988
88931 90388 0
153878 127005 0
51428 146698 0
47233 44294 0
165647 94047 0
166749 168430 0
72728 87056 0
166749 113491 0
53604 116732 0
124969 120242 0
149669 118248 0
132892 45646 0
159774 167127 0
166749 148203 0
166749 129635 0
144811 121866 0
79510 144556 0
12541 75600 0
166749 ...

output:


result:

wrong output format Unexpected end of file - token expected

Subtask #8:

score: 0
Wrong Answer

Test #36:

score: 0
Wrong Answer
time: 44ms
memory: 14664kb

input:

169178 200000 1
108026 106006 1
130712 146166 1
103490 133909 1
168608 113741 1
113670 115210 1
41692 127482 1
88594 91086 1
73606 78011 1
47848 99392 1
138615 97485 1
133884 131888 1
126125 47540 1
42576 147882 1
105365 109903 1
71043 153403 1
104808 113745 1
63589 160217 1
52766 161917 1
112636 13...

output:


result:

wrong output format Unexpected end of file - token expected

Subtask #9:

score: 0
Skipped

Dependency #5:

0%