QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#69755 | #1067. TOLL | feecle6418 | 100 ✓ | 1110ms | 21228kb | C++14 | 2.4kb | 2022-12-31 16:41:05 | 2022-12-31 16:41:06 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Edge{
int x,y,z,id;
}e[300005],te[55],ee[55];
struct E{
int to,id;
};
int n,m,K,fa[100005],isrep[300005],a[100005],F[100005],fv[100005];
int d[100005],ts,bel[100005],cnt,M,nd[300005];
ll sz[100005],val[100005],ans=0,sum=0;
vector<E> g[100005],G[100005];
int gf(int x){
return x==fa[x]?x:fa[x]=gf(fa[x]);
}
void dfs1(int x,int fa){
if(x==ee[fa].x)F[x]=ee[fa].y;
else F[x]=ee[fa].x;
fv[x]=fa,d[x]=d[F[x]]+1;
for(E i:G[x]){
int y=i.to;
if(y==F[x])continue;
dfs1(y,i.id);
}
}
void Get(int x,int y,int z){
int mx=0,tx=x,ty=y;
while(x!=y){
if(d[x]<d[y])swap(x,y);
ee[fv[x]].z=min(ee[fv[x]].z,z),x=F[x];
}
}
void dfs2(int x,int fa){
val[cnt]+=a[x],bel[x]=cnt;
for(E i:g[x]){
int y=i.to;
if(y==fa)continue;
dfs2(y,x);
}
}
void dfs3(int x,int fa){
sz[x]=val[x];
for(E i:G[x]){
int y=i.to;
if(y==fa)continue;
dfs3(y,x),sz[x]+=sz[y];
if(ee[i.id].id<=K)sum+=1ll*ee[i.id].z*sz[y];
}
}
ll Calc(){
for(int i=1;i<=cnt;i++)fa[i]=i,G[i].clear();
for(int i=1;i<=M;i++){
int x=gf(ee[i].x),y=gf(ee[i].y);
if(x==y){
nd[i]=1;
continue;
}
fa[x]=y,G[ee[i].x].push_back({ee[i].y,i}),G[ee[i].y].push_back({ee[i].x,i});
if(!ee[i].z)ee[i].z=1e9;
}
sum=0,dfs1(bel[1],0);
for(int i=1;i<=M;i++)if(nd[i])Get(ee[i].x,ee[i].y,ee[i].z),nd[i]=0;
dfs3(bel[1],0);
return sum;
}
int main(){
scanf("%d%d%d",&n,&m,&K);
for(int i=1,x,y,z;i<=m;i++)scanf("%d%d%d",&x,&y,&z),e[i]={x,y,z,i};
for(int i=1;i<=n;i++)fa[i]=i;
for(int i=1,x,y,z;i<=K;i++){
scanf("%d%d",&x,&y),te[++ts]={x,y,0};
x=gf(x),y=gf(y),fa[x]=y;
}
sort(e+1,e+m+1,[](Edge x,Edge y){return x.z<y.z;});
for(int i=1;i<=m;i++){
int x=gf(e[i].x),y=gf(e[i].y);
if(x==y)continue;
fa[x]=y,g[e[i].x].push_back({e[i].y,i}),g[e[i].y].push_back({e[i].x,i});
}
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
for(int i=1;i<=n;i++){
if(bel[i])continue;
cnt++,dfs2(i,0);
}
for(int i=1;i<=K;i++)te[i].x=bel[te[i].x],te[i].y=bel[te[i].y];
for(int i=1;i<=m;i++)e[i].x=bel[e[i].x],e[i].y=bel[e[i].y];
for(int i=1;i<=cnt;i++)fa[i]=i;
for(int i=1;i<=m;i++){
int x=gf(e[i].x),y=gf(e[i].y);
if(x==y)continue;
fa[x]=y,te[++ts]=e[i],te[ts].id=ts;
}
for(int i=0;i<(1<<K);i++){
M=0;
for(int j=1;j<=K;j++)if(i&(1<<j-1))ee[++M]=te[j];
for(int j=K+1;j<=ts;j++)ee[++M]=te[j];
ans=max(ans,Calc());
}
cout<<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: 13812kb
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: 2ms
memory: 10380kb
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: 0ms
memory: 10336kb
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: 13656kb
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: 4ms
memory: 14008kb
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: 4ms
memory: 13504kb
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: 154ms
memory: 21228kb
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: 153ms
memory: 19528kb
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: 132ms
memory: 19204kb
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: 738ms
memory: 21020kb
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: 1092ms
memory: 21056kb
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: 1110ms
memory: 19176kb
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