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

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

#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. Python(1) 整型与浮动型

    整型与浮动型 整数/浮动数=浮点型整数/整数 = 浮点型 例如:>>> type(1/1)<class 'float'>>>> type(1/1.0)& ...

  2. 浅析拯救小矮人的 nlogn 算法及其证明

    浅析拯救小矮人的 nlogn 算法及其证明 题型简介: 有 $ n $ 个人,第 $ i $ 个人身高 $ a_i $ 手长 $ b_i $ ,他们为了从一个高为 $ H $ 的洞中出去,决定搭人梯. ...

  3. 自学semantic UI个人博客首页模板

    以下是代码 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <m ...

  4. git-shell设置代理

    Configure Git to use a proxy ##In Brief You may need to configure a proxy server if you're having tr ...

  5. CobaltStrike + Metasploit 联动使用

    本节的知识摘要: 通过 beacon内置的 socks功能将本地 Msf直接代入目标内网 借助 CobaltStrike的外部 tcp监听器通过 ssh隧道直接派生一个 meterpreter到本地 ...

  6. Quantitative Startegies for Achieving Alpha(二)

    Chapter 3 The Day-To-Day Drivers Of Stock Market Returns Summary: (1) Earning growth is the primary ...

  7. React Native 之react-native-sqlite-storage

    npm 官网指导: https://www.npmjs.com/package/react-native-sqlite-storage 1. 执行: npm install react-native- ...

  8. Software-Defined Networking: A Comprehensive Survey

    文章名称:Software-Defined Networking: A Comprehensive Survey 文章来源:Proceedings of the IEEE ( Volume: 103  ...

  9. No plugin found for prefix 'war' in the current project and in the plugin groups

    解决办法: 在pom里面添加 : <dependency> <groupId>org.apache.maven.plugins</groupId> <arti ...

  10. 深入探究JVM(1) - Java的内存区域解析

    http://blog.csdn.net/sczyh22/article/details/46652901<br>Java 虚拟机在执行Java程序的时候会把它管理的内存区域划为几部分,这 ...