Hub Connection plan

Time Limit:1000MS Memory Limit:65536KB
Total Submit:743 Accepted:180

Description

Partychen is working as system administrator and is planning to establish a new network in his company. There will be N hubs in the company, they can be connected to each other using cables. Since each worker of the company must have access to the whole network, each hub must be accessible by cables from any other hub (with possibly some intermediate hubs).
Since cables of different types are available and shorter ones are cheaper, it is necessary to make such a plan of hub connection, that the cost is minimal. partychen will provide you all necessary information about possible hub connections. You are to help partychen to find the way to connect hubs so that all above conditions are satisfied.

Input

The first line of the input contains two integer numbers: N - the number of hubs in the network (2 <= N <= 1000) and M - the number of possible hub connections (1 <= M <= 15000). All hubs are numbered from 1 to N. The following M lines contain information about possible connections - the numbers of two hubs, which can be connected and the cable cost required to connect them. cost is a positive integer number that does not exceed 106. There will always be at least one way to connect all hubs.

Output

Output the minimize cost of your hub connection plan.

Sample Input

4 6
1 2 1
1 3 1
1 4 2
2 3 1
3 4 1
2 4 1

Sample Output

3
Hint
We can build net from 1 to 2 to 3 to 4,then we get the cost is 3.Of course you can get 3 by other way.

Source

解题:最小生成树模板

 #include <bits/stdc++.h>
using namespace std;
const int maxn = ;
struct arc{
int u,v,w;
bool operator<(const arc &t)const{
return w < t.w;
}
}e[maxn];
int uf[maxn],n,m;
int Find(int x){
if(x != uf[x]) uf[x] = Find(uf[x]);
return uf[x];
}
int main(){
while(~scanf("%d %d",&n,&m)){
for(int i = ; i < m; ++i)
scanf("%d%d%d",&e[i].u,&e[i].v,&e[i].w);
sort(e,e+m);
int ret = ;
for(int i = ; i <= n; ++i) uf[i] = i;
for(int i = ; i < m; ++i){
int x = Find(e[i].u);
int y = Find(e[i].v);
if(x == y) continue;
ret += e[i].w;
uf[x] = y;
}
printf("%d\n",ret);
}
return ;
}

ECNUOJ 2573 Hub Connection plan的更多相关文章

  1. Network 分类: POJ 图论 2015-07-27 17:18 17人阅读 评论(0) 收藏

    Network Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 14721 Accepted: 5777 Special Judg ...

  2. URAL 1160 Network(最小生成树)

    Network Time limit: 1.0 secondMemory limit: 64 MB Andrew is working as system administrator and is p ...

  3. Network()

    Network Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 60000/30000K (Java/Other) Total Submi ...

  4. POJ 1861 Network (模版kruskal算法)

    Network Time Limit: 1000MS Memory Limit: 30000K Total Submissions: Accepted: Special Judge Descripti ...

  5. ZOJ 1542 POJ 1861 Network 网络 最小生成树,求最长边,Kruskal算法

    题目连接:problemId=542" target="_blank">ZOJ 1542 POJ 1861 Network 网络 Network Time Limi ...

  6. POJ-1861-NETWORK 解题报告

    Network Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 16628   Accepted: 6597   Specia ...

  7. POJ 1861:Network(最小生成树&amp;&amp;kruskal)

    Network Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 13266   Accepted: 5123   Specia ...

  8. poj1681 Network

    题目链接 https://cn.vjudge.net/problem/17712/origin Andrew is working as system administrator and is pla ...

  9. OJ题解记录计划

    容错声明: ①题目选自https://acm.ecnu.edu.cn/,不再检查题目删改情况 ②所有代码仅代表个人AC提交,不保证解法无误 E0001  A+B Problem First AC: 2 ...

随机推荐

  1. js 40 个技巧

    1. oncontextmenu="window.event.returnValue=false" 将彻底屏蔽鼠标右键<table border oncontextmenu= ...

  2. Python3基础笔记---面向对象

    只是对一些新的知识的记录 1.创建类 class ClassName: <statement-1> . . . <statement-N> 类实例化后,可以使用其属性,实际上, ...

  3. OpenJDK源码研究笔记(五)-缓存Integer等类型的频繁使用的数据和对象,大幅度提升性能(一道经典的Java笔试题)

    摘要 本文先给出一个看似很简单实则有深意的Java笔试面试题,引出JDK内部的缓存. JDK内部的缓存,主要是为了提高Java程序的性能. 你能答对这道"看似简单,实则有深意"的J ...

  4. 北京联通光猫WO-36(HG220GS-U)改为桥接模式

    家里弄了个极路由,想在公司里去操作路由器,交换文件.提前下载电影什么的,因此需要光猫改为桥接模式,让路由器拨号 由于WO-36(HG220GS-U)这个型号的光猫固件升级后(我的是3.x)不能用工程账 ...

  5. HDU 4288-Coder(模拟)

    Coder Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Su ...

  6. 树莓派安装node.js

    因为树莓派是arm架构,node.js上并没有提供arm架构的二进制包下载. 试过使用apt包管理安装和直接node.js源代码编译安装(编译了四五个小时...),都没有成功,报非法指令错误,预计还是 ...

  7. Java常用知识(长期更新)

    1.0转义符 \n:换行 ,\n的作用和print后面的ln相同,可酌情使用 \t:一个制表位(一系列空格) 例: public class Schedule{ public static void ...

  8. 如何解读「量子计算应对大数据挑战:中国科大首次实现量子机器学习算法」?——是KNN算法吗?

    作者:知乎用户链接:https://www.zhihu.com/question/29187952/answer/48519630 我居然今天才看到这个问题,天……本专业,有幸听过他们这个实验的组会来 ...

  9. Tuples as return values

    Strictly speaking, a function can only return one value, but if the value is a tuple, the effect is ...

  10. windows下python3 使用cx_Oracle,xlrd插件进行excel数据清洗录入

    我们在做数据分析,清洗的过程中,很多时候会面对各种各样的数据源,要针对不同的数据源进行清洗,入库的工作.当然python这个语言,我比较喜欢,开发效率高,基本上怎么写都能运行,而且安装配置简单,基本上 ...