ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#194257 | #3415. 生成花朵 | sunchenyu2012 | 100 | 2316ms | 11464kb | C++ | 691b | 2023-10-15 10:10:58 | 2023-10-15 12:24:23 |
answer
#include<iostream>
#include<cstdio>
#include<algorithm>
#define ll long long
#define N 500005
using namespace std;
struct node{
int a,b;
ll c;
}e[N];
ll sum=0LL;
int f[N],n,m,k;
bool p[N];
bool cmp(node x,node y){
return x.c>y.c;
}inline int find(int x){
if(f[x]==x)return x;
return f[x]=find(f[x]);
}int main(){
scanf("%d%d%d",&n,&m,&k);
for(int i=1;i<=n;i++)f[i]=i;
for(int i=1;i<=m;i++)scanf("%d%d%lld",&e[i].a,&e[i].b,&e[i].c);
sort(e+1,e+m+1,cmp);
for(int i=1;i<=m;i++){
int u=find(e[i].a),v=find(e[i].b);
if(u!=v&&(p[u]+p[v]<!k+1)||(k==0&&!p[u]&&u==v)){
p[v]=(p[u]||p[v]||(u==v)),f[u]=v,sum+=e[i].c;
}
}printf("%lld",sum);
return 0;
}
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1212kb
input:
15 20 1 6 7 963580 12 5 716228 4 1 403343 14 3 457011 7 1 436546 7 2 5466 15 4 475864 2 1 336271 10 ...
output:
8081145
result:
ok single line: '8081145'
Test #2:
score: 10
Accepted
time: 0ms
memory: 1220kb
input:
20 20 0 20 4 432617 4 3 629590 10 16 943103 19 18 497537 10 20 416253 6 16 115921 19 10 28488 11 15 ...
output:
9008387
result:
ok single line: '9008387'
Test #3:
score: 10
Accepted
time: 310ms
memory: 11456kb
input:
500000 500000 1 444008 222356 414783 222356 51288 425686 135088 494686 95472 51288 444008 160817 512...
output:
208774404701
result:
ok single line: '208774404701'
Test #4:
score: 10
Accepted
time: 300ms
memory: 11412kb
input:
490000 500000 1 96647 180570 271064 36008 360162 653861 270823 314031 502346 360162 317315 931956 48...
output:
207785443393
result:
ok single line: '207785443393'
Test #5:
score: 10
Accepted
time: 238ms
memory: 11452kb
input:
500000 500000 0 108208 98102 1 202388 305044 1 379342 59163 1 379342 202388 1 363727 379342 1 202388...
output:
381245
result:
ok single line: '381245'
Test #6:
score: 10
Accepted
time: 240ms
memory: 11440kb
input:
496666 500000 0 197894 345096 1 94268 107852 1 94268 197894 1 370883 197894 1 345096 370883 1 94268 ...
output:
376663
result:
ok single line: '376663'
Test #7:
score: 10
Accepted
time: 291ms
memory: 11464kb
input:
500000 500000 0 7736 74162 726251 345417 74162 913705 74162 170609 539950 204696 7736 414420 7736 34...
output:
212883906779
result:
ok single line: '212883906779'
Test #8:
score: 10
Accepted
time: 303ms
memory: 10980kb
input:
400000 500000 0 22826 70883 154409 203647 70883 812518 317370 59895 163272 203647 22826 283183 31737...
output:
204726430556
result:
ok single line: '204726430556'
Test #9:
score: 10
Accepted
time: 326ms
memory: 10496kb
input:
300000 500000 0 227622 219467 110779 205687 9592 959582 113992 227622 988579 219467 113992 606597 21...
output:
186656418583
result:
ok single line: '186656418583'
Test #10:
score: 10
Accepted
time: 308ms
memory: 10732kb
input:
350000 500000 0 252737 211924 582239 300699 14041 390756 300699 220584 650566 273799 14041 277337 67...
output:
198608090311
result:
ok single line: '198608090311'
Extra Test:
score: 0
Extra Test Passed