QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#711437 | #4272. Phone Plans | shuopihua | 0 | 271ms | 102640kb | C++14 | 2.2kb | 2024-11-05 10:57:20 | 2024-11-05 10:57:20 |
Judging History
answer
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <unordered_map>
#define int long long
using namespace std;
int n,A,B,K,m;
int fa[200005];
int ww[200005];
int ss[200005];
int bl[200005];
vector <int> g[200005];
vector <int> d[200005];
vector <int> p[200005];
struct node{int u,v,w;};
node a[200005];
node b[200005];
unordered_map <int,int> mp[200005];
inline int Find(int x){return fa[x]==x?x:fa[x]=Find(fa[x]);}
inline void in(int &n){
n=0;
char c=getchar();
while(c<'0' || c>'9') c=getchar();
while(c>='0'&&c<='9') n=n*10+c-'0',c=getchar();
return ;
}
signed main(){
in(n),in(A),in(B),in(K);
if(K==0){puts("0");return 0;}
for(int i=1;i<=A;i++) in(a[i].u),in(a[i].v),in(a[i].w);
for(int i=1;i<=B;i++) in(b[i].u),in(b[i].v),in(b[i].w);
sort(a+1,a+1+A,[](node p,node q){return p.w<q.w;});
sort(b+1,b+1+B,[](node p,node q){return p.w<q.w;});
for(int i=1;i<=n;i++) fa[i]=i,g[i].emplace_back(i);
for(int i=1;i<=B;i++){
int r=i;
while(r<=B&&b[i].w==b[r].w) r++;
r--;
ww[++m]=b[i].w;
ss[m]=ss[m-1];
while(i<=r){
int u=Find(b[i].u),v=Find(b[i].v);
i++;
if(u==v) continue;
ss[m]+=1ll*g[v].size()*g[u].size();
if(g[v].size()>g[u].size()) swap(u,v);
for(int vv:g[v]) g[u].emplace_back(vv);
fa[v]=u;
p[m].emplace_back(v);
}
i--;
}
for(int i=1;i<=n;i++) bl[i]=Find(i);
for(int i=1;i<=n;i++) fa[i]=i,d[i].emplace_back(i),mp[i][bl[i]]=1;
a[A+1].w=1e15;
int ans=1e18,X=0,Y=0,pos=1;
for(int i=m;i>=1;i--){
while(pos<=A&&X+ss[i]-Y<K){
int u=Find(a[pos].u),v=Find(a[pos].v);
pos++;
if(u==v) continue;
if(d[v].size()>d[u].size()) swap(u,v);
X+=1ll*d[v].size()*d[u].size();
for(int vv:d[v]){
mp[v][bl[vv]]--;
Y-=mp[v][bl[vv]];
Y+=mp[u][bl[vv]];
mp[u][bl[vv]]++;
d[u].emplace_back(vv);
}
fa[v]=u;
}
if(X+ss[i]-Y>=K) ans=min(ans,ww[i]+a[pos-1].w);
else break;
for(int v:p[i]){
for(int vv:g[v]){
mp[Find(vv)][bl[vv]]--;
Y-=mp[Find(vv)][bl[vv]];
bl[vv]=v;
Y+=mp[Find(vv)][bl[vv]];
mp[Find(vv)][bl[vv]]++;
}
}
}
printf("%lld\n",ans>2e9?-1:ans);
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 6
Accepted
time: 3ms
memory: 36492kb
input:
6 4 4 9 1 2 1 2 3 2 1 4 3 3 4 4 5 6 40 1 5 30 2 6 20 3 6 10
output:
33
result:
ok single line: '33'
Test #2:
score: 6
Accepted
time: 3ms
memory: 31376kb
input:
1 0 0 0
output:
0
result:
ok single line: '0'
Test #3:
score: 6
Accepted
time: 0ms
memory: 36852kb
input:
2 0 0 1
output:
-1
result:
ok single line: '-1'
Test #4:
score: 0
Wrong Answer
time: 0ms
memory: 36292kb
input:
2 10 10 1 1 1 915886339 2 2 430624192 1 1 879808770 1 2 577221915 1 1 439429731 1 2 304911826 1 1 148009333 1 2 51122687 1 1 558282772 1 2 421196385 2 1 436692145 1 2 654020563 2 2 162573477 2 2 989531779 1 1 646687051 2 2 549037477 2 2 699532275 1 1 679375858 2 1 83352965 2 1 415698228
output:
83352965
result:
wrong answer 1st lines differ - expected: '51122687', found: '83352965'
Subtask #2:
score: 0
Wrong Answer
Test #53:
score: 5
Accepted
time: 166ms
memory: 95628kb
input:
200000 100000 100000 7628995 23677 113459 839167193 165893 15365 669621527 26287 109671 214795757 156871 136723 522277985 9957 100463 806718116 104783 161385 156110975 184577 92225 545172629 57373 130083 980035338 167231 49597 919886451 115601 24325 717233004 99413 141311 737488449 83437 62759 76873...
output:
502149991
result:
ok single line: '502149991'
Test #54:
score: 5
Accepted
time: 47ms
memory: 81896kb
input:
200000 200000 87 2694 197233 86229 181875035 85167 196363 328068482 177795 65479 693403443 119609 181977 588691030 115815 139981 486110961 92473 20483 199129328 166989 95385 210368646 98095 54673 357307451 122543 94377 907487846 46611 80735 71787832 158893 117071 521262491 92051 104395 365725125 142...
output:
11965880
result:
ok single line: '11965880'
Test #55:
score: 5
Accepted
time: 171ms
memory: 93620kb
input:
200000 103 199999 1593 75203 150269 64 68675 175215 100 176335 11837 94 33623 63279 56 16617 86741 63 167219 52783 58 6575 134399 1 144065 114171 2 32625 99459 50 35311 152509 36 132975 12211 8 175275 107903 23 17477 21319 95 157759 66683 71 34577 78339 26 154003 26703 18 187863 90945 74 116071 1089...
output:
7037526
result:
ok single line: '7037526'
Test #56:
score: 5
Accepted
time: 4ms
memory: 31596kb
input:
1 0 0 0
output:
0
result:
ok single line: '0'
Test #57:
score: 5
Accepted
time: 4ms
memory: 32812kb
input:
1 1 0 0 1 1 1
output:
0
result:
ok single line: '0'
Test #58:
score: 5
Accepted
time: 4ms
memory: 35472kb
input:
2 0 0 1
output:
-1
result:
ok single line: '-1'
Test #59:
score: 5
Accepted
time: 42ms
memory: 44008kb
input:
2 200000 200000 1 1 1 540311820 1 1 825820034 1 1 555157427 1 1 288420080 1 1 672135630 1 1 726777321 1 1 526670467 1 1 959728057 1 1 146842949 1 1 122695951 1 1 432194433 1 1 381185144 1 1 686598677 1 1 215624542 1 1 458312135 1 1 986262083 1 1 947920916 1 1 934427659 1 1 782364899 1 1 715992893 1 ...
output:
-1
result:
ok single line: '-1'
Test #60:
score: 5
Accepted
time: 24ms
memory: 41188kb
input:
2 200000 200000 1 1 1 1000000000 1 1 1000000000 1 1 1000000000 1 1 1000000000 1 1 1000000000 1 1 1000000000 1 1 1000000000 1 1 1000000000 1 1 1000000000 1 1 1000000000 1 1 1000000000 1 1 1000000000 1 1 1000000000 1 1 1000000000 1 1 1000000000 1 1 1000000000 1 1 1000000000 1 1 1000000000 1 1 10000000...
output:
-1
result:
ok single line: '-1'
Test #61:
score: 5
Accepted
time: 110ms
memory: 91920kb
input:
200000 0 200000 352487 135712 118584 670867088 72546 31680 1279343 123412 184392 678367510 125022 192330 57001931 134050 61434 212353526 6066 95972 717546833 47726 9232 949490922 166856 33998 986508808 166254 92344 143252836 82392 100980 919436840 84316 12292 753153826 192154 134452 832321404 144418...
output:
216679869
result:
ok single line: '216679869'
Test #62:
score: 0
Wrong Answer
time: 56ms
memory: 80652kb
input:
200000 200000 0 1089706 197033 84309 947754387 112807 60173 477333202 102607 132751 957665006 143619 102001 642146230 32419 155751 770317403 53835 4703 414754921 9463 17929 312775978 172373 41459 29632969 48451 142975 596586913 36019 180115 791609008 145487 162325 699635731 177243 94157 221311090 18...
output:
-1
result:
wrong answer 1st lines differ - expected: '245598855', found: '-1'
Subtask #3:
score: 0
Wrong Answer
Test #103:
score: 6
Accepted
time: 0ms
memory: 30168kb
input:
1 0 0 0
output:
0
result:
ok single line: '0'
Test #104:
score: 6
Accepted
time: 3ms
memory: 36852kb
input:
2 0 0 1
output:
-1
result:
ok single line: '-1'
Test #105:
score: 6
Accepted
time: 25ms
memory: 40964kb
input:
2 10 200000 1 2 1 319832429 1 1 412617159 2 1 337734185 1 2 674652880 1 2 454610992 2 2 688717944 1 1 189208056 2 2 951221780 1 2 594191431 2 2 87592160 1 2 833491749 2 2 732961971 2 1 575969648 2 2 268359887 2 1 436382098 1 2 514959278 1 2 305446083 1 2 365989813 1 2 296840111 1 1 541558213 1 1 497...
output:
10104
result:
ok single line: '10104'
Test #106:
score: 6
Accepted
time: 14ms
memory: 39120kb
input:
2 10 200000 1 1 1 1000000000 1 1 1000000000 1 2 1000000000 1 2 1000000000 1 2 1000000000 1 1 1000000000 2 1 1000000000 2 2 1000000000 2 2 1000000000 2 2 1000000000 1 1 1000000000 1 2 1000000000 1 1 1000000000 2 1 1000000000 1 1 1000000000 1 1 1000000000 2 1 1000000000 1 1 1000000000 2 2 1000000000 2...
output:
1000000000
result:
ok single line: '1000000000'
Test #107:
score: 6
Accepted
time: 214ms
memory: 101692kb
input:
200000 10 200000 17900 199675 76237 290240030 50211 6922 761990536 92097 120746 607490 192856 130409 616541101 50427 80049 330957286 129588 180294 466199684 8674 110653 155297749 91380 156344 798960399 102127 40858 801752583 94673 105892 152356242 185676 6183 263664373 169026 112948 812501808 93517 ...
output:
75425485
result:
ok single line: '75425485'
Test #108:
score: 6
Accepted
time: 90ms
memory: 88740kb
input:
200000 10 200000 11791021341 90115 14234 985783971 123477 154651 628493605 123171 47179 220847663 8072 163826 30383173 174753 12792 15862638 172837 96919 880800330 92696 166466 443031361 85298 185851 999558577 23737 111350 809362300 24551 127050 920973896 121483 145215 67814677 78536 41919 475800490...
output:
949367959
result:
ok single line: '949367959'
Test #109:
score: 6
Accepted
time: 184ms
memory: 98940kb
input:
200000 0 200000 423432 117280 87297 405090778 161764 93979 279208002 169095 190396 237565477 5136 81072 251360373 177384 130645 595157997 5282 38206 898866303 150431 96891 829055730 18413 42187 599085995 75585 47004 557307885 92187 77157 349172549 63029 186638 993483250 37685 198246 538754012 119056...
output:
404806867
result:
ok single line: '404806867'
Test #110:
score: 6
Accepted
time: 24ms
memory: 79100kb
input:
200000 10 0 1583868 66186 49114 583417488 79347 122356 957296935 4161 178945 973881307 39875 85386 62804962 62164 81798 964069340 6410 188411 31431750 67426 6153 513781110 49101 116783 513947988 61043 89483 259723608 14116 90504 23294861
output:
-1
result:
ok single line: '-1'
Test #111:
score: 6
Accepted
time: 75ms
memory: 90128kb
input:
200000 10 200000 19999900000 47625 147346 8 147346 121067 9 97009 179826 2 155552 97009 1 179826 22149 3 15370 4310 5 135552 47625 7 121067 131030 10 4310 135552 6 22149 15370 4 92707 136627 90227 20274 369 174990 32793 164281 194588 56508 95231 92612 117675 125225 114617 42843 81551 39780 149173 15...
output:
199999
result:
ok single line: '199999'
Test #112:
score: 6
Accepted
time: 78ms
memory: 88092kb
input:
200000 10 200000 19999900000 45665 143462 7 22696 184210 2 38538 57388 9 184210 154285 3 125307 22696 1 149825 71332 5 143462 38538 8 154285 149825 4 57388 182077 10 71332 45665 6 163095 156887 174710 77920 77020 63954 85503 109613 119638 46319 118285 60934 66569 45264 83574 73519 101885 163357 1583...
output:
200000
result:
ok single line: '200000'
Test #113:
score: 6
Accepted
time: 73ms
memory: 88108kb
input:
200000 10 200000 19999900000 739 28876 199992 53663 1295 199998 43161 52504 200000 158247 739 199993 2816 184328 199996 52504 53663 199999 1295 2816 199997 52726 158247 199994 28876 8395 199991 184328 52726 199995 130045 124454 95456 117404 39359 188185 42676 84681 4828 105147 95150 194669 17107 579...
output:
199999
result:
ok single line: '199999'
Test #114:
score: 6
Accepted
time: 78ms
memory: 88152kb
input:
200000 10 200000 19999900000 19794 183474 199991 71973 145759 199999 167290 188987 199995 6730 167290 199996 92616 6730 199997 93098 157369 199993 145759 92616 199998 104691 71973 200000 157369 19794 199992 188987 93098 199994 4529 33398 169717 116172 158258 118532 69720 25407 140713 173220 192301 1...
output:
200000
result:
ok single line: '200000'
Test #115:
score: 6
Accepted
time: 4ms
memory: 32072kb
input:
200000 0 0 0
output:
0
result:
ok single line: '0'
Test #116:
score: 6
Accepted
time: 31ms
memory: 76796kb
input:
200000 0 0 1
output:
-1
result:
ok single line: '-1'
Test #117:
score: 6
Accepted
time: 32ms
memory: 76456kb
input:
200000 0 0 19999900000
output:
-1
result:
ok single line: '-1'
Test #118:
score: 6
Accepted
time: 0ms
memory: 31984kb
input:
200000 10 200000 0 146668 190255 646706475 71516 174249 65976309 173393 55930 434227341 38682 164404 792088710 68045 174249 105770742 190255 24008 378601596 68045 174249 584120597 68045 68045 891140070 71516 71516 121444300 24008 173393 638520585 42552 123134 440551564 172416 148702 205154389 80345 ...
output:
0
result:
ok single line: '0'
Test #119:
score: 6
Accepted
time: 220ms
memory: 102280kb
input:
200000 10 200000 1 18089 125148 634373061 26320 138377 746998187 125148 130407 287480602 136290 4926 478063834 136333 147458 29423436 26320 147458 334115471 4926 136290 505364255 18089 26320 866606210 11249 77957 605205962 136333 11249 440411926 170380 191070 819377443 150060 41355 635345633 143709 ...
output:
2407
result:
ok single line: '2407'
Test #120:
score: 6
Accepted
time: 265ms
memory: 102232kb
input:
200000 10 200000 4 131932 102405 14740950 95390 60349 599957231 62719 96049 468132040 96049 196778 435897371 147221 147221 710991146 69099 139866 753644389 130732 22961 374767514 118319 62719 793210617 14592 172623 872022637 131932 147221 588107750 133618 115753 634870732 69458 144612 651075961 8687...
output:
14977
result:
ok single line: '14977'
Test #121:
score: 6
Accepted
time: 271ms
memory: 102460kb
input:
200000 10 200000 92 26204 41682 132397613 11386 43267 432400482 26204 145442 188527020 124727 65248 170978952 26613 172005 567702196 146166 39798 679712885 146166 39798 953781917 124727 41682 826584416 146166 146166 117167249 65248 11386 787325743 764 17622 571020090 171608 112618 89050875 21593 172...
output:
473019
result:
ok single line: '473019'
Test #122:
score: 6
Accepted
time: 219ms
memory: 101972kb
input:
200000 10 200000 672 151843 72188 754208507 186567 155545 192251945 72188 173580 807040666 173580 155545 413157526 143249 143249 343025568 143249 182692 983484260 182692 21150 153868493 173580 155545 648383151 151843 182692 108954433 156381 14221 612434692 8027 76055 276048757 29885 107311 354554984...
output:
3501158
result:
ok single line: '3501158'
Test #123:
score: 6
Accepted
time: 261ms
memory: 102376kb
input:
200000 10 200000 5413 95488 104057 66278284 58623 58623 818395626 99093 124205 414738887 99093 158331 881420357 159736 67384 193983425 67384 58623 623301482 159736 141485 530044249 158331 146846 170069165 95488 158331 521843529 144566 99093 996200413 47960 153496 68751236 48094 54076 759978913 2873 ...
output:
25561771
result:
ok single line: '25561771'
Test #124:
score: 6
Accepted
time: 179ms
memory: 99004kb
input:
200000 10 200000 607219 117398 78777 25237306 122250 107989 217199414 100967 69009 323823567 78777 78777 653032486 43957 47258 709036359 107989 30352 736599336 152731 47258 974489271 69009 122250 631296609 69009 43957 982998301 164327 117398 451874824 78667 87007 949453372 176540 180070 825887209 29...
output:
424224418
result:
ok single line: '424224418'
Test #125:
score: 6
Accepted
time: 151ms
memory: 97108kb
input:
200000 10 200000 38942692 191843 87774 48763750 42448 181646 153085306 78078 10204 342154140 42448 45480 342538264 51194 78078 40436760 95235 39182 532944349 79153 79153 495283828 108632 141932 193232728 78078 121421 507359193 141932 108632 799596562 141888 166667 289423598 62108 182515 150884302 43...
output:
506971462
result:
ok single line: '506971462'
Test #126:
score: 6
Accepted
time: 122ms
memory: 93416kb
input:
200000 10 200000 3867596036 101129 178836 611548548 71053 23325 51723100 23325 197101 732184179 113289 40120 919460669 71053 12789 146285015 37966 23325 463373360 40120 12789 690404961 34895 40120 689138722 178836 12789 350156365 40120 23325 969795259 64088 12703 150877304 125299 69683 377982548 190...
output:
659435029
result:
ok single line: '659435029'
Test #127:
score: 6
Accepted
time: 100ms
memory: 90504kb
input:
200000 10 200000 19999900000 19948 93224 696463523 187941 81537 209135633 70892 81537 80053781 24348 139884 806003775 187941 73976 934692473 167817 167817 45539332 93456 24348 405608615 173940 167817 358543555 70892 73976 806171243 24348 173940 495263721 143061 46638 446762613 89043 9162 584904381 4...
output:
-1
result:
ok single line: '-1'
Test #128:
score: 6
Accepted
time: 8ms
memory: 32836kb
input:
200000 10 200000 0 51897 141304 64 125281 55107 6 160539 169899 18 55107 125281 75 134103 100791 22 134103 92211 69 169899 55107 78 125281 55107 78 110799 51897 127287266 169899 134103 85 137999 70531 886030502 126853 67828 763444764 6746 128867 630841156 131235 16144 483070630 75851 127161 25109450...
output:
0
result:
ok single line: '0'
Test #129:
score: 0
Wrong Answer
time: 239ms
memory: 102640kb
input:
200000 10 200000 1 132839 73305 8 66415 66415 90 57701 174971 79 66415 174971 18 183186 132839 19 89931 89931 61 179694 73305 40 73305 174971 6 17869 89931 81 73305 132839 840562812 125249 112893 879029614 194877 19061 138829945 81475 120055 169500004 11311 70715 654559512 188750 172969 324123184 17...
output:
8
result:
wrong answer 1st lines differ - expected: '6', found: '8'
Subtask #4:
score: 0
Skipped
Dependency #1:
0%