QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#733715 | #5824. Himitsu | ffffyc | 0 | 1114ms | 24260kb | C++14 | 2.4kb | 2024-11-10 20:37:22 | 2024-11-10 20:37:24 |
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,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: 0
Wrong Answer
time: 0ms
memory: 11780kb
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 -65940632895472 15 224996156768272
result:
wrong answer 2nd lines differ - expected: '16', found: '-65940632895472'
Test #2:
score: 0
Wrong Answer
time: 0ms
memory: 11740kb
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 -65940632895212 276 197821898686741 263762531582233 374993594614047
result:
wrong answer 2nd lines differ - expected: '276', found: '-65940632895212'
Test #3:
score: 0
Wrong Answer
time: 1ms
memory: 11776kb
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 131881265791006 197821898686498 263762531581991 374993594613805
result:
wrong answer 3rd lines differ - expected: '30', found: '131881265791006'
Test #4:
score: 0
Wrong Answer
time: 1078ms
memory: 22252kb
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 66009001149052 131949679023410 197890371705535 263831183501605 329772080550252 395713018580180 461653977508111 527594957591644 593767878881432 660207136959331 726221194096389 792235271229512 893815990039333 1027505896135876 1101603395193098 1175039488740009 1248475600956337 1321911797015...
result:
wrong answer 2nd lines differ - expected: '68368253564', found: '66009001149052'
Test #5:
score: 0
Wrong Answer
time: 1114ms
memory: 22152kb
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 34761093817502 69451810678392 104142540874611 138833348087376 173524160200851 208214988823600 242905861280098 277596799049283 312519706770280 347708970115327 382473036649464 450067841143560 553564335951493 596141026285026 638717716785219 681294461233839 723871210464564 766447993029703 80...
result:
wrong answer 2nd lines differ - expected: '70642967710', found: '34761093817502'
Test #6:
score: 0
Wrong Answer
time: 1106ms
memory: 24260kb
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 -73719229306878 -147546189114240 -221373100515056 -295199943976386 -369026779484480 -442853573916214 -481143709457128 -531133265941612 -597538164891479 -663943050657854 -730347936320667 -796752807070158 -863157642330352 -929562468476917 -995967242842678 -1062371921032694 -11279734390267...
result:
wrong answer 2nd lines differ - expected: '106963544066', found: '-73719229306878'
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 ...