QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#733716 | #5824. Himitsu | ffffyc | 60 | 1169ms | 28504kb | C++14 | 2.4kb | 2024-11-10 20:37:47 | 2024-11-10 20:37:48 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
namespace IO{//by cyffff
int len=0;
char ibuf[(1<<21)+1],*iS,*iT,out[(1<<25)+1];
#if ONLINE_JUDGE
#define gh() (iS==iT?iT=(iS=ibuf)+fread(ibuf,1,(1<<21)+1,stdin),(iS==iT?EOF:*iS++):*iS++)
#else
#define gh() getchar()
#endif
#define reg register
inline int read(){
reg char ch=gh();
reg int x=0;
reg char t=0;
while(ch<'0'||ch>'9') t|=ch=='-',ch=gh();
while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=gh();
return t?-x:x;
}
inline void putc(char ch){
out[len++]=ch;
}
template<class T>
inline void write(T x){
if(x<0)putc('-'),x=-x;
if(x>9)write(x/10);
out[len++]=x%10+48;
}
inline void flush(){
fwrite(out,1,len,stdout);
len=0;
}
inline char getc(){
char ch=gh();
while(ch<'A'||ch>'Z') ch=gh();
return ch;
}
}
using IO::read;
using IO::write;
using IO::flush;
using IO::getc;
using IO::putc;
#define pii pair<int,int>
#define mpr make_pair
#define fir first
#define sec second
const int N=1e4+10,M=1e6+10;
struct Edge{
int u,v;
ll w;
inline friend bool operator<(const Edge &a,const Edge &b){
return a.w<b.w;
}
}a[M],b[M],c[M],d[M];
int n,m,k,c1,c2,c3;
struct DSU{
int fa[N],siz[N];
inline void init(int n){
for(int i=1;i<=n;i++)
siz[fa[i]=i]=1;
}
inline int find(int x){
return x==fa[x]?x:fa[x]=find(fa[x]);
}
inline bool unnion(int x,int y){
x=find(x),y=find(y);
if(x==y) return 0;
if(siz[x]<siz[y]) swap(x,y);
fa[y]=x,siz[x]+=siz[y];
return 1;
}
}D;
inline ll calc(ll x){
for(int i=1;i<=c2;i++)
c[i]={b[i].u,b[i].v,b[i].w-x};
merge(a+1,a+c1+1,c+1,c+c2+1,d+1);
D.init(n);
ll s=0;
for(int i=1;i<=m;i++)
if(D.unnion(d[i].u,d[i].v))
s+=d[i].w;
return s;
}
inline ll solve(int k){
ll L=-1e14,R=1e14;
while(L<R){
ll mL=L+R>>1,mR=mL+1;
ll v1=calc(mL)+1ll*mL*k,v2=calc(mR)+1ll*mR*k;
if(v1==v2) return v1;
if(v1<v2) L=mL+1;
else R=mR-1;
}
return calc(L)+1ll*L*k;
}
int main(){
n=read(),m=read(),k=read();
for(int i=1;i<=k;i++){
int u=read(),v=read(),w=read();
b[++c2]={u,v,w};
}
for(int i=k+1;i<=m;i++){
int u=read(),v=read(),w=read();
a[++c1]={u,v,w};
}
sort(a+1,a+c1+1);
sort(b+1,b+c2+1);
D.init(n);
for(int i=1;i<=c1;i++)
if(D.unnion(a[i].u,a[i].v))
d[++c3]=a[i];
for(int i=1;i<=c3;i++)
a[i]=d[i];
c1=c3;
for(int i=0;i<=k;i++)
write(solve(i)),putc('\n');
flush();
}
詳細信息
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 2ms
memory: 11836kb
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: 11864kb
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: 0ms
memory: 11900kb
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: 1138ms
memory: 28444kb
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: 1169ms
memory: 28428kb
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: 1146ms
memory: 28504kb
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: 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 ...