QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#104834 | #5824. Himitsu | sichengzhou | 20 | 2ms | 5652kb | C++14 | 1.2kb | 2023-05-12 02:52:54 | 2023-05-12 02:52:55 |
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;
LL c;
bool operator <(const edge &t)const
{
return c<t.c;
}
}e[M],e1[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;
}
LL ans[N];
void dnq(int L,int R,int l,int r)
{
// printf("dnq(%d,%d,%d,%d)\n",L,R,l,r);
if(l>r||L>R)
{
return ;
}
int mid=(L+R)>>1;
for(int i=1;i<=m;i++)
{
e1[i]=e[i];
if(i<=K)
{
e1[i].c=e[i].c+mid;
}
}
sort(e1+1,e1+m+1);
LL val=0;
int cnt=0;
init();
for(int i=1;i<=m;i++)
{
if(merge(e1[i].u,e1[i].v))
{
val+=e1[i].c;
if(e1[i].id<=K)
{
cnt++;
}
}
}
ans[cnt]=val-mid*cnt;
dnq(L,mid-1,cnt+1,r);
dnq(mid+1,R,l,cnt-1);
}
int main()
{
scanf("%d%d%d",&n,&m,&K);
for(int i=1;i<=m;i++)
{
e[i].id=i;
scanf("%d%d%lld",&e[i].u,&e[i].v,&e[i].c);
}
dnq(-1e9,1e9,0,K);
for(int i=0;i<=K;i++)
{
printf("%d\n",ans[i]);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 10
Accepted
time: 2ms
memory: 5636kb
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: 2ms
memory: 5652kb
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: 0
Wrong Answer
time: 2ms
memory: 5648kb
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 0 45
result:
wrong answer 5th lines differ - expected: '39', found: '0'
Test #4:
score: 0
Time Limit Exceeded
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:
result:
Test #5:
score: 0
Time Limit Exceeded
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:
result:
Test #6:
score: 0
Time Limit Exceeded
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:
result:
Test #7:
score: 0
Time Limit Exceeded
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:
result:
Test #8:
score: 0
Time Limit Exceeded
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:
result:
Test #9:
score: 0
Time Limit Exceeded
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:
result:
Test #10:
score: 0
Time Limit Exceeded
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 ...