好吧这个题没什么可说的,有点....

  一开始还和一位大佬在讨论,会不会有多余的边,后面看了题发现没有多于的边和自环,所以之间一波最大生成树把最大的边去掉,把最小的边推倒就行了。

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int maxn = + , maxm = + ;
int n, m, ans, head[maxn];
bool vis[maxm];
struct Edge {
int u, v, w;
} edge[maxm]; bool cmp(const Edge &a, const Edge &b) {
return a.w > b.w;
} int Find(int x) {
if(x == head[x]) return x;
else return head[x] = Find(head[x]);
} int main() {
int x, y;
while(~scanf("%d %d", &n, &m)) {
ans = ;
memset(vis, false, sizeof vis);
for(int i = ; i <= n; i ++) {
scanf("%d %d", &x, &y);
head[i] = i;
}
for(int i = ; i < m; i ++) {
scanf("%d %d %d", &edge[i].u, &edge[i].v, &edge[i].w);
}
sort(edge, edge + m, cmp);
int cnt = , num = ;
for(int i = ; i < m; i ++) {
int fx = Find(edge[i].u), fy = Find(edge[i].v);
if(fx != fy) {
cnt ++;
head[fx] = fy;
vis[i] = true;
}
if(cnt == n - ) break;
}
for(int i = ; i < m; i ++) {
if(!vis[i]) {
ans += edge[i].w;
num ++;
}
}
printf("%d %d\n", num, ans);
}
return ;
}

HDU-6187.DestroyWalls(最大生成树)的更多相关文章

  1. HDU 6187 Destroy Walls (思维,最大生成树)

    HDU 6187 Destroy Walls (思维,最大生成树) Destroy Walls *Time Limit: 8000/4000 MS (Java/Others) Memory Limit ...

  2. HDU - 6187 (最大生成树) 最小生成树

    Destroy Walls Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others) ...

  3. HDU 6187 Destroy Walls (对偶图最小生成树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6187 题意:有一个V个结点M条边的带边权无向平面图,有一个人在一个区域,要拆一些墙使得他可以到达任意一 ...

  4. HDU 4786 Fibonacci Tree(生成树,YY乱搞)

    http://acm.hdu.edu.cn/showproblem.php? pid=4786 Fibonacci Tree Time Limit: 4000/2000 MS (Java/Others ...

  5. hdu 3367 Pseudoforest(最大生成树)

    Pseudoforest Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) To ...

  6. HDU 6187 Destroy Walls

    Destroy Walls Long times ago, there are beautiful historic walls in the city. These walls divide the ...

  7. hdu 3367(与最大生成树无关。无关。无关。重要的事情说三遍+kruskal变形)

    Pseudoforest Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tot ...

  8. HDU 4786 Fibonacci Tree 生成树

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=4786 题意:有N个节点(1 <= N <= 10^5),M条边(0 <= M <= ...

  9. hdu 3367 Pseudoforest 最大生成树★

    #include <cstdio> #include <cstring> #include <vector> #include <algorithm> ...

随机推荐

  1. QueryDSL通用查询框架学习目录

    转载自恒宇的博客 https://www.jianshu.com/p/99a5ec5c3bd5

  2. font-awesome样式只显示方框

    这是一个踩过的坑:使用font-awesome中的css样式库时,比如fa-user-circle-o,显示的不是一个用户图标,而是一个方框. 怎么回事呢? 进入css文件,发现: 咦,这些文件呢?我 ...

  3. Win10离线安装.NET Framework 3.5的方法补充(附cab格式离线安装包下载) - 转载

    MS酋长很早以前已经分享了<Win10离线安装.NET Framework 3.5的方法技巧>,同时分享了exe格式的.NET Framework 3.5离线安装包下载地址.但有部分网友反 ...

  4. 七夕-心形表白-简单css代码

    今天你要和谁过? 今天你要怎么过?? 今天去哪里吃??? 公司的三连问,对于一些单身狗有点招架不住啊. 在此送上一个薄礼,来安慰下受伤的心灵... 确定是安慰不是连环打击嘛..... 回答:确定! 来 ...

  5. #433 Div2 Problem C Planning (贪心 && 优先队列)

    链接 : http://codeforces.com/contest/854/problem/C 题意 : 有 n 架飞机需要分别在 1~n 秒后起飞,允许起飞的时间是从 k 秒后开始,给出每一架飞机 ...

  6. 获取第几个class

    假如类名为a,如果是同级(兄弟元素)的,如:<ul><li class='a'></li><li class='a'></li></u ...

  7. 旧题再做【bzoj2287】【[pojchallenge]消失之物】分治背包

    (上不了p站我要死了) 今天听了 doggu神 讲了这道题的另一种做法,真是脑洞大开.眼界大开.虽然复杂度比黄学长的要大一点,但不总结一下简直对不起这神思路. 方法1:黄学长的做法(点这里) Desc ...

  8. Leetcode 8. String to Integer (atoi)(模拟题,水)

    8. String to Integer (atoi) Medium Implement atoi which converts a string to an integer. The functio ...

  9. (20)C++项目练习三--------【运动物体视频检测跟踪系统】

    1.功能点 (1)视频监控显示 (2)移动物体标定跟踪(轨迹显示) (3)实时视频保存(以时间戳形式) (4)移动物体触发视频保存.报警 (5)视频文件分类.回放.搜索 进行中............ ...

  10. centos 6.x 安装配置 node.js 环境

    下载 可以在本地下载node.js最新版,然后通过ftp工具上传到服务器,或者直接在服务器终端使用wget命令下载(我当时下载的是node-v6.11.3-linux-x64版本,其他版本请查看上面链 ...