QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#313409#1067. TOLLlgvc100 ✓820ms17944kbC++142.5kb2024-01-24 18:44:052024-01-24 18:44:05

Judging History

你现在查看的是测评时间为 2024-01-24 18:44:05 的历史记录

  • [2024-11-07 12:40:37]
  • 管理员手动重测本题所有提交记录
  • 测评结果:100
  • 用时:879ms
  • 内存:18456kb
  • [2024-01-24 18:44:05]
  • 评测
  • 测评结果:100
  • 用时:820ms
  • 内存:17944kb
  • [2024-01-24 18:44:05]
  • 提交

answer

#include <bits/stdc++.h>
long long ss[300009],sz[300009],nm[25];
int N,M,K,a[25],b[25],id2[300009],id[300009],qq,qq2,pa[200009],
hd[300009],to[50],nxt[50],val[50],k,tp[300009],dep[300009],as[25];
inline void l(int u,int v,int w) {
	to[++k]=v;nxt[k]=hd[u];val[k]=w;hd[u]=k;
}
inline int fr(int x) {
	while(x!=pa[x]) x=pa[x]=pa[pa[x]];
	return x;
}
inline void co(int x,int y) {
	if(fr(x)!=fr(y)) pa[fr(x)]=fr(y);
}
struct n_t{
	int a,b,c;
} f[300009];
void dfs(int n,int f) {
	pa[n]=f;dep[n]=dep[f]+1;sz[n]=ss[n];
	for(int i=hd[n];i;i=nxt[i]) {
		if(to[i]==f) continue;
		tp[to[i]]=val[i];
		dfs(to[i],n);
		sz[n]+=sz[to[i]];
	}
	nm[tp[n]]=sz[n];
}
inline bool cmp(n_t x,n_t y) {
	return x.c<y.c;
}
signed main(void) {
	scanf("%d %d %d",&N,&M,&K);
	for(int i=1;i<=M;i++) {
		scanf("%d %d %d",&f[i].a,&f[i].b,&f[i].c);
	}
	std::sort(f+1,f+M+1,cmp);
	for(int i=1;i<=N+N;i++) pa[i]=i;
	for(int i=1;i<=K;i++) {
		scanf("%d %d",&a[i],&b[i]);
		co(a[i],b[i]);
	}
	for(int i=1;i<=M;i++) {
		if(fr(f[i].a)!=fr(f[i].b)) {
			id2[++qq2]=i;
			pa[fr(f[i].a)]=fr(f[i].b);
			pa[fr(f[i].a+N)]=fr(f[i].b+N);
		} else if(fr(f[i].a+N)!=fr(f[i].b+N)) {
			id[++qq]=i;
			pa[fr(f[i].a+N)]=fr(f[i].b+N);
		} 
	}
	for(int i=1;i<=N;i++) pa[i]=i;
	for(int i=1;i<=qq2;i++) {
		co(f[id2[i]].a,f[id2[i]].b);
	}
	for(int i=1;i<=qq;i++) {
		f[id[i]].a=fr(f[id[i]].a);
		f[id[i]].b=fr(f[id[i]].b);
	}
	for(int i=1;i<=N;i++) {
		int sz;scanf("%d",&sz);ss[fr(i)]+=sz;
	}
	for(int i=1;i<=K;i++) a[i]=fr(a[i]),b[i]=fr(b[i]);
	int rt=fr(1);
	long long ans=0;
	for(int i=1;i<(1<<K);i++) {
		k=0;
		bool zz=0;
		for(int k=1;k<=qq;k++) pa[f[id[k]].a]=f[id[k]].a,hd[f[id[k]].a]=0;
		for(int k=1;k<=qq;k++) pa[f[id[k]].b]=f[id[k]].b,hd[f[id[k]].b]=0;		
		for(int j=1;j<=K;j++) {
			if((i>>j-1)&1) {
				l(a[j],b[j],j);
				l(b[j],a[j],j);
				if(fr(a[j])==fr(b[j])) {
					zz=1;
					break;
				} else pa[fr(a[j])]=fr(b[j]);
			}
		}
		if(zz) continue;
		int qq2=0;
		for(int j=1;j<=qq;j++) {
			if(fr(f[id[j]].a)!=fr(f[id[j]].b)) {
				l(f[id[j]].a,f[id[j]].b,0);
				l(f[id[j]].b,f[id[j]].a,0);
				pa[fr(f[id[j]].a)]=fr(f[id[j]].b);
			} else id2[++qq2]=id[j];
		}
		dfs(rt,0);
		memset(as,0x3f,sizeof(as));
		for(int j=1;j<=qq2;j++) {
			int x=f[id2[j]].a,y=f[id2[j]].b;
			while(x!=y) {
				if(dep[x]<dep[y]) std::swap(x,y);
				if(tp[x]) as[tp[x]]=std::min(as[tp[x]],f[id2[j]].c);
				x=pa[x];
			}
		}
		long long at=0;
		for(int j=1;j<=K;j++) if((i>>j-1)&1) at+=1ll*nm[j]*as[j];
		ans=std::max(ans,at);
	}
	printf("%lld",ans);
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 100
Accepted

Test #1:

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

input:

10 20 1
9 10 378587
3 10 283693
10 1 276961
8 1 828871
6 3 814717
3 5 701468
4 8 116841
7 5 859891
2 5 973550
9 2 460881
6 5 260184
8 9 895822
3 8 864166
10 4 746770
6 9 818592
7 1 748443
6 2 308698
6 7 170433
6 1 854347
2 10 641070
8 2
739814 240233 280283 628215 946109 596323 536584 590185 294679 ...

output:

909864568000

result:

ok single line: '909864568000'

Test #2:

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

input:

8 20 1
7 2 707898
6 4 739797
6 1 921019
7 3 739954
2 6 26438
5 4 242350
8 5 147225
7 6 53026
2 5 18161
5 1 319852
8 1 928770
6 5 291033
6 8 870601
3 5 596483
4 8 769617
1 4 516480
3 8 960359
2 3 672639
7 8 951165
3 4 911419
7 5
485318 528016 310567 880656 812984 803814 654959 289193

output:

34729855934

result:

ok single line: '34729855934'

Subtask #2:

score: 100
Accepted

Dependency #1:

100%
Accepted

Test #3:

score: 100
Accepted
time: 2ms
memory: 10036kb

input:

26 50 10
10 16 402572
16 17 883196
13 26 698082
5 16 96211
11 16 642512
16 22 44910
5 2 928962
3 24 834337
2 12 56104
18 1 851938
4 14 441768
6 21 793020
25 7 341805
7 22 664203
25 19 671175
8 7 362800
7 6 377915
21 20 975066
8 4 264657
4 26 445906
9 26 821755
18 9 285249
3 17 120207
11 15 816139
23...

output:

26876914464865

result:

ok single line: '26876914464865'

Test #4:

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

input:

30 50 10
24 16 369496
5 2 882195
24 23 579700
24 1 795457
7 10 903779
13 21 98625
27 24 857438
2 26 795121
21 15 117380
10 6 168591
12 2 439190
4 3 631680
18 24 785210
2 16 558732
22 26 215162
4 2 399966
15 2 203973
1 30 206852
12 10 263496
28 29 122008
6 19 593874
1 28 729019
11 14 346091
11 13 859...

output:

9136801138069

result:

ok single line: '9136801138069'

Subtask #3:

score: 100
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Test #5:

score: 100
Accepted
time: 3ms
memory: 12132kb

input:

996 4996 10
170 989 243014
721 287 359761
610 423 788736
585 466 513618
554 793 156587
994 825 688447
674 781 762434
508 572 562510
483 869 533334
180 16 760074
128 555 198218
505 477 764496
812 950 933017
956 352 68500
380 453 597965
386 461 73627
912 813 520584
127 912 542464
633 614 869565
466 57...

output:

12830368594279

result:

ok single line: '12830368594279'

Test #6:

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

input:

996 4997 9
88 459 699265
66 726 399273
15 881 921567
780 731 428735
961 840 375485
136 307 332102
667 455 536024
212 370 303328
825 923 766355
244 633 628367
511 971 847795
158 670 931260
863 820 696866
387 414 457843
600 397 514798
983 588 127138
667 177 450185
805 542 524896
142 842 173512
590 989...

output:

131916901593944

result:

ok single line: '131916901593944'

Subtask #4:

score: 100
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Test #7:

score: 100
Accepted
time: 99ms
memory: 15244kb

input:

99999 300000 15
8263 74744 351158
99994 1858 959312
51293 12648 410986
50988 66305 124816
78339 46383 472656
23067 36177 124594
25316 11071 650426
20116 66491 337820
56050 92136 776255
63863 4856 145398
56147 58709 59835
92779 46842 597998
67356 4992 976781
18754 15659 747827
50592 32564 974934
4057...

output:

674157150571257

result:

ok single line: '674157150571257'

Test #8:

score: 0
Accepted
time: 98ms
memory: 17944kb

input:

99997 299997 15
15086 8272 317654
51688 54086 925693
79393 44246 733165
5121 99554 940009
73819 74687 300136
28135 99512 729766
17724 3230 16816
7175 67002 133099
79164 63244 281638
80811 53391 247073
36469 8629 26781
34858 87099 405285
28026 30409 138012
2033 37209 102857
47202 87346 152415
50932 6...

output:

24969716835311373

result:

ok single line: '24969716835311373'

Test #9:

score: 0
Accepted
time: 98ms
memory: 16048kb

input:

99998 299996 15
92044 25170 648129
80059 96640 888347
74422 53399 735265
74474 30014 659633
60006 71490 105530
33305 67230 854383
28825 77262 619529
59991 31479 93123
95700 55692 702097
51099 19406 98145
58858 15465 352917
91120 22132 120191
93857 28179 57758
5140 96513 70872
8385 10647 94137
39516 ...

output:

27631318393017517

result:

ok single line: '27631318393017517'

Subtask #5:

score: 100
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Test #10:

score: 100
Accepted
time: 533ms
memory: 17684kb

input:

100000 299998 20
96038 13455 411806
34273 46237 121800
37816 45499 152136
66614 97068 632185
33093 37063 341112
18567 90031 42759
13592 33972 544036
19075 28170 803755
75682 59080 805802
96474 30020 576324
39190 81518 900617
28771 52586 649619
29548 19634 824228
24855 59532 9471
14656 39015 178564
2...

output:

36368416031036

result:

ok single line: '36368416031036'

Test #11:

score: 0
Accepted
time: 820ms
memory: 17848kb

input:

99997 299999 20
79337 15573 857181
12712 83282 30933
49804 51826 733141
51322 60281 610372
12270 92783 702034
7691 39247 143682
97221 16780 73719
3897 7607 266238
94581 1008 711580
24326 2587 464921
74258 94622 6157
47527 39962 687977
84629 855 465735
69661 3498 233590
25486 80895 881536
40996 63452...

output:

12419905230277678

result:

ok single line: '12419905230277678'

Test #12:

score: 0
Accepted
time: 774ms
memory: 16652kb

input:

99999 300000 20
98194 88041 285236
36713 83692 611444
78892 80049 669118
83918 13086 895200
42441 37140 22886
17620 42337 493671
51752 76143 776467
16294 99157 990715
69781 83842 493793
36423 32311 134593
41380 7826 469279
98790 69623 52306
78225 35165 969168
40268 91474 93243
83892 51362 271404
924...

output:

14360308274743226

result:

ok single line: '14360308274743226'

Subtask #6:

score: 16.6667
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted