CH模拟赛 拆地毯
/*
MST,注意只能加K条边,但是备选是M条边
*/
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define ll long long
#define fo(i,l,r) for(int i = l;i <= r;i++)
#define fd(i,l,r) for(int i = r;i >= l;i--)
using namespace std;
const int N = ;
ll read(){
ll x=,f=;
char ch=getchar();
while(!(ch>=''&&ch<='')){if(ch=='-')f=-;ch=getchar();};
while(ch>=''&&ch<=''){x=x*+(ch-'');ch=getchar();};
return x*f;
}
struct edge{
int u,v;ll w;
}e[N*];
int n,m,k,cnt,head[N],f[N];ll ans;
bool cmp(edge a,edge b){return a.w > b.w;}
int findf(int x) {return f[x] == x ? f[x] : f[x] = findf(f[x]);}
int main(){
freopen("carpet.in","r",stdin);
freopen("carpet.out","w",stdout);
n =read();m=read();k=read();
int u,v;ll w;
fo(i,,m){
e[i].u=read();e[i].v=read();e[i].w=read();
}
sort(e+,e++m,cmp);
fo(i,,n) f[i] = i;
int fa,fb;
fo(i,,m){
fa = findf(e[i].u);fb=findf(e[i].v);
if(fa != fb){
f[fa] = fb,ans += e[i].w;
k--;
}
if(!k) break;
}
cout<<ans;
return ;
}
CH模拟赛 拆地毯的更多相关文章
- CH模拟赛 皇后游戏
/* 做的时候手推了一下n=2的四种情况,再排一下序就可以了,证明不是很严谨,但我想这就行了,毕竟全是套路 */ #include<iostream> #include<cstdio ...
- CH模拟赛 还教室
/* 区间操作,可以推一推式子,方差为平方的平均数-平均数的平方,维护区间和与区间平方和,平方和的维护方法类似,式子推一推就行了,注意约分 */ #include<iostream> #i ...
- CH Round #52 - Thinking Bear #1 (NOIP模拟赛)
A.拆地毯 题目:http://www.contesthunter.org/contest/CH%20Round%20%2352%20-%20Thinking%20Bear%20%231%20(NOI ...
- 队爷的讲学计划 CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的讲学计划 题解:刚开始理解题意理解了好半天,然后发 ...
- 队爷的Au Plan CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的Au%20Plan 题解:看了题之后觉得肯定是DP ...
- 队爷的新书 CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的新书 题解:看到这题就想到了 poetize 的封 ...
- CH Round #58 - OrzCC杯noip模拟赛day2
A:颜色问题 题目:http://ch.ezoj.tk/contest/CH%20Round%20%2358%20-%20OrzCC杯noip模拟赛day2/颜色问题 题解:算一下每个仆人到它的目的地 ...
- CH Round #49 - Streaming #4 (NOIP模拟赛Day2)
A.二叉树的的根 题目:http://www.contesthunter.org/contest/CH%20Round%20%2349%20-%20Streaming%20%234%20(NOIP 模 ...
- CH Round #48 - Streaming #3 (NOIP模拟赛Day1)
A.数三角形 题目:http://www.contesthunter.org/contest/CH%20Round%20%2348%20-%20Streaming%20%233%20(NOIP模拟赛D ...
随机推荐
- 2-ser2003系统封装实验报告
Ser2003需要挂载系统镜像 至此,ser2003的母盘制作完成!!! 来自为知笔记(Wiz) 附件列表
- Linux下如何遍历指定目录下的所有文件并删除指定天数之前创建的文件
脚本内容如下: #!/bin/bash function delete_file { days=$[$-] for i in `find $dir -type f -ctime +$days` do ...
- [No00008A]bat改变cmd命令提示符颜色
从Windows 95到现在的Windows 10,系统中带的DOS命令提示符软件都是黑白画面,下面教大家几个自定义DOS命令提示符颜色的小技巧. 改变DOS命令提示符的标题:在开始菜单点运行,输入 ...
- CodeAtlas For Sublime Text
CodeAtlas is a plugin of SublimeText, which allows one to explore the call graph conveniently. The p ...
- 虚拟机上装uoj
前期准备: x64 ubuntu 镜像.vmware.ss账号 注意一定要有64位镜像! ss不是必须的,不过没有的话就等着下载一晚上吧... 首先先装好ubuntu,我装的是ubuntu-16.04 ...
- 台式机装原版Win2008R2
台式机装原版Win2008R2 坑了老半天,总结出几点 1,系统os下载: http://msdn.itellyou.cn/ 注:其他地方下载的,装后发现不是起不来就是驱动装不了. 2,u盘里放个压缩 ...
- django ORM的外键操作
外键约束示例 #models操作如下 class HostInfo(models.Model): servername = models.CharField(max_length=) serverip ...
- [LeetCode] Summary Ranges 总结区间
Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...
- [LeetCode] Read N Characters Given Read4 II - Call multiple times 用Read4来读取N个字符之二 - 多次调用
The API: int read4(char *buf) reads 4 characters at a time from a file. The return value is the actu ...
- 琴弦文字 - wpf行为
效果图: 此效果的设计和实现思路均来自:上位者的怜悯 详情见原文:http://www.cnblogs.com/lianmin/p/5940637.html 我所做的,只是将原作者的设计和思路封装成了 ...