QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#720154 | #5824. Himitsu | mengzdd | 100 ✓ | 276ms | 30780kb | C++14 | 1.8kb | 2024-11-07 10:56:07 | 2024-11-07 10:56:08 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1e4+4,M=1e6+6;
int n,m,K;
struct edge{
int u,v,id;
double c;
bool operator <(const edge &t)const
{
return c<t.c;
}
}e[M],e1[M],e2[M];
int fa[N];
void init()
{
for(int i=1;i<=n;i++)
{
fa[i]=i;
}
}
int getfa(int x)
{
if(x==fa[x])
{
return x;
}
return fa[x]=getfa(fa[x]);
}
bool merge(int x,int y)
{
x=getfa(x);y=getfa(y);
if(x==y)
{
return 0;
}
fa[x]=y;
return 1;
}
double ans[N];
void dnq(double L,double R,int l,int r)
{
// printf("dnq(%lf,%lf,%d,%d)\n",L,R,l,r);
if(l>r)
{
return ;
}
double mid=(L+R)/2;
double val=0;
int cnt=0;
init();
int i=1,j=1;
while(i<=K&&j<=m)
{
if(e[i].c+mid<e2[j].c)
{
if(merge(e[i].u,e[i].v))
{
cnt++;
val+=e[i].c+mid;
}
i++;
}else{
if(merge(e2[j].u,e2[j].v))
{
val+=e2[j].c;
}
j++;
}
// cout<<i<<' '<<j<<endl;
}
// getchar();
while(i<=K)
{
if(merge(e[i].u,e[i].v))
{
val+=e[i].c+mid;
cnt++;
}
i++;
}
while(j<=m)
{
if(merge(e2[j].u,e2[j].v))
{
val+=e2[j].c;
}
j++;
}
ans[cnt]=val-mid*cnt;
dnq(L,mid,cnt+1,r);
dnq(mid,R,l,cnt-1);
}
int main()
{
scanf("%d%d%d",&n,&m,&K);
for(int i=1;i<=K;i++)
{
e[i].id=i;
scanf("%d%d%lf",&e[i].u,&e[i].v,&e[i].c);
}
for(int i=1;i<=m-K;i++)
{
e1[i].id=i;
scanf("%d%d%lf",&e1[i].u,&e1[i].v,&e1[i].c);
}
m-=K;
sort(e+1,e+K+1);
sort(e1+1,e1+m+1);
init();
int tot=0;
for(int i=1;i<=m;i++)
{
if(merge(e1[i].u,e1[i].v))
{
e2[++tot]=e1[i];
// cout<<e1[i].u<<' '<<e1[i].v<<endl;
}
}
// cout<<"**\n";
// return 0;
m=n-1;
dnq(-1e9,1e9,0,K);
for(int i=0;i<=K;i++)
{
printf("%.0lf\n",ans[i]);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 0ms
memory: 7964kb
input:
6 9 3 2 4 4 1 5 3 6 3 5 1 2 2 2 3 7 3 5 3 3 4 2 5 6 6 4 5 4
output:
20 16 15 16
result:
ok 4 lines
Test #2:
score: 10
Accepted
time: 0ms
memory: 7976kb
input:
100 400 5 53 9 3 62 78 9 31 35 6 72 93 8 86 90 4 30 31 8 9 41 9 60 61 5 95 99 9 97 99 8 70 83 2 46 48 10 33 34 6 34 35 4 22 54 5 28 69 2 62 81 7 49 87 7 16 55 2 51 52 2 6 30 3 61 62 9 50 51 10 73 82 3 48 49 6 53 80 7 63 78 2 68 69 10 12 53 5 70 100 2 64 68 9 62 76 6 93 95 7 6 7 3 44 76 7 40 43 5 68 ...
output:
277 276 276 277 281 287
result:
ok 6 lines
Test #3:
score: 10
Accepted
time: 1ms
memory: 7984kb
input:
10 40 5 7 6 9 2 10 8 4 8 10 9 3 2 1 5 5 7 8 6 5 9 2 3 7 10 5 6 4 3 8 5 1 2 8 3 6 9 3 6 8 4 8 9 7 9 8 7 9 7 4 5 5 3 8 7 8 9 4 1 8 3 7 9 6 2 10 6 2 9 7 9 10 2 6 8 5 2 5 4 2 6 10 6 10 5 5 10 5 3 9 4 3 5 6 5 8 7 3 4 10 7 9 7 5 9 10 6 7 3 8 10 10 7 10 4 2 3 4 1 9 8
output:
31 29 30 34 39 45
result:
ok 6 lines
Test #4:
score: 10
Accepted
time: 260ms
memory: 30580kb
input:
10000 1000000 20 673 8529 925916638 4467 9106 778815144 4956 1061 191186606 6398 8505 749954687 4228 4936 437336750 1472 3659 364376596 8911 8279 985814372 1080 2483 475516379 2191 5167 473958713 3830 2482 315079222 3686 2602 273536687 9705 6949 851752141 7775 1208 66207907 6650 8254 413300231 1679 ...
output:
68356278688 68368253564 68413232434 68473019071 68651919653 68916072812 69221207252 69547239695 69894427740 70254588056 70663564131 71073361669 71503155272 71950447397 72409521348 73132787978 73875507881 74636897201 75482129664 76391229990 77369563668
result:
ok 21 lines
Test #5:
score: 10
Accepted
time: 271ms
memory: 30540kb
input:
9998 1000000 20 3050 7224 785359967 369 9689 607993111 6896 8178 539140101 612 1021 866917365 2978 4959 433003169 6023 6870 172017705 4549 9330 617305834 1133 7920 387746815 1209 8529 507217461 9595 3075 746633949 4664 3479 822136956 2475 6087 618279848 4063 5468 689195043 9021 2256 361464631 5018 1...
output:
70478917578 70642967710 70908978808 71188325235 71544688208 71905951891 72283724848 72705331554 73192250947 73720888168 74317177087 74918417400 75527607048 76195483269 76875011554 77554706499 78288349871 79026775348 79798535239 80608325204 81448372457
result:
ok 21 lines
Test #6:
score: 10
Accepted
time: 258ms
memory: 28732kb
input:
9998 1000000 20 1 2 281450128 3 4 189470595 5 6 654103262 7 8 567873660 9 10 924945310 11 12 812485062 13 14 349389614 15 16 590413589 17 18 714997695 19 20 497902926 21 22 603700643 23 24 811173440 25 26 603597081 27 28 833261051 29 30 398419210 31 32 357342850 33 34 663216891 35 36 233043582 37 38...
output:
107774073471 106963544066 106196587648 105478037776 104827427390 104184770240 103583189450 103081092376 102648966036 102239379625 101842976706 101446677349 101065291314 100719394576 100382611467 100097609162 99908782602 99721267664 99554528715 99398845462 99323790772
result:
ok 21 lines
Test #7:
score: 10
Accepted
time: 268ms
memory: 30684kb
input:
10000 1000000 50 6125 6203 386561950 5051 1107 596451416 8639 6378 818193218 7624 4370 606455506 8172 7412 596283734 3620 7063 364663757 2643 5033 600368957 754 4761 566428495 5787 6703 708028562 6426 8148 13916053 2557 8196 803475919 3234 554 46664629 8129 3021 26804160 3632 7861 517537760 9630 657...
output:
70596141195 70586554158 70594694383 70610129935 70630695197 70664572044 70747361906 70843170058 70975134386 71114117309 71259997335 71425031346 71609819895 71803250606 72114795822 72431859895 72789052376 73157959563 73535405701 73913552181 74298772516 74684790044 75143503996 75628204535 76113198180 ...
result:
ok 51 lines
Test #8:
score: 10
Accepted
time: 253ms
memory: 30780kb
input:
9999 1000000 50 4404 3111 318693352 7700 9479 391610819 6706 2267 98084108 1782 8998 853063825 6570 4092 117937800 8317 7129 925418971 6424 3691 590402665 7115 4780 962699607 3021 4241 318239757 8462 4719 823926976 5074 4153 971136 6618 561 597011893 9718 80 426359721 5521 7717 676102225 531 4785 69...
output:
69827514551 69818263862 69829062032 69843548902 69871938060 69909442371 69976746462 70049674479 70128987590 70216457531 70321857770 70435668532 70633978866 70896730835 71166043862 71463663353 71767538685 72089616585 72412918921 72799989209 73187771138 73594245063 74001347019 74413428188 74857473007 ...
result:
ok 51 lines
Test #9:
score: 10
Accepted
time: 261ms
memory: 30712kb
input:
10000 1000000 50 1 2 400001413 3 4 101650475 5 6 41788922 7 8 425542000 9 10 699416488 11 12 231847939 13 14 705366080 15 16 86222619 17 18 55218159 19 20 765606555 21 22 186347194 23 24 384893832 25 26 509646590 27 28 153572539 29 30 938382597 31 32 82098718 33 34 154929117 35 36 557472291 37 38 83...
output:
167910696965 166936638568 165978427490 165033645649 164095181932 163177280650 162263503269 161365153744 160518726283 159673655400 158837638976 158023986170 157224795100 156456643039 155736459222 155027622340 154379855825 153764749657 153162093897 152561121063 151961122476 151366951569 150792493569 1...
result:
ok 51 lines
Test #10:
score: 10
Accepted
time: 276ms
memory: 28724kb
input:
9999 1000000 50 1 2 225799568 3 4 934016518 5 6 301486474 7 8 81882482 9 10 489832491 11 12 816874660 13 14 268129137 15 16 885143997 17 18 269748960 19 20 482266443 21 22 465732893 23 24 195691027 25 26 362417760 27 28 188030259 29 30 328917464 31 32 614931828 33 34 222284961 35 36 362779633 37 38 ...
output:
166758234557 165807500498 164858773654 163928071903 163009954385 162123339717 161268751596 160439345759 159622624760 158810655019 158006346046 157228631007 156454430575 155702907291 154955358716 154223487853 153493236813 152767223135 152068709609 151372196070 150680939779 150008053626 149336971090 1...
result:
ok 51 lines
Extra Test:
score: 0
Extra Test Passed