ECNUOJ 2573 Hub Connection plan
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的更多相关文章
- Network 分类: POJ 图论 2015-07-27 17:18 17人阅读 评论(0) 收藏
Network Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 14721 Accepted: 5777 Special Judg ...
- URAL 1160 Network(最小生成树)
Network Time limit: 1.0 secondMemory limit: 64 MB Andrew is working as system administrator and is p ...
- Network()
Network Time Limit : 2000/1000ms (Java/Other) Memory Limit : 60000/30000K (Java/Other) Total Submi ...
- POJ 1861 Network (模版kruskal算法)
Network Time Limit: 1000MS Memory Limit: 30000K Total Submissions: Accepted: Special Judge Descripti ...
- ZOJ 1542 POJ 1861 Network 网络 最小生成树,求最长边,Kruskal算法
题目连接:problemId=542" target="_blank">ZOJ 1542 POJ 1861 Network 网络 Network Time Limi ...
- POJ-1861-NETWORK 解题报告
Network Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 16628 Accepted: 6597 Specia ...
- POJ 1861:Network(最小生成树&&kruskal)
Network Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 13266 Accepted: 5123 Specia ...
- poj1681 Network
题目链接 https://cn.vjudge.net/problem/17712/origin Andrew is working as system administrator and is pla ...
- OJ题解记录计划
容错声明: ①题目选自https://acm.ecnu.edu.cn/,不再检查题目删改情况 ②所有代码仅代表个人AC提交,不保证解法无误 E0001 A+B Problem First AC: 2 ...
随机推荐
- Android程序能够构建和运行,但是报以下报错,为什么?
安卓程序写完之后能够构建和运行,但是会报以下的错误.不知道原因为何?求大神解答. 网上说的是混淆编译的原因,不过程序没有开启混淆编译. Error:warning: Ignoring InnerCla ...
- 3ds Max实例教程-制作卡通蓝色小人
此篇教程分享使用3ds Max制作卡通蓝色小人,是根据作者梦境出现的画面为原型,加以改造,得到的最终效果图. 创作一张图最重要的地方是先用纸和笔画出草稿图.你需要表明所有的细节,研究角色的特点——我发 ...
- nodejs 封装mysql连接池
写在前面的 在nodejs后台代码中,我们总是会和数据库打交道 然而,每次都要写数据库的配置以及连接和断开,不胜其烦 我就封装了一个连接池模块,不足之处还请多多批评 上代码 一下是写在mysqls.j ...
- NodeJS学习笔记 (7)网络服务-http-client(ok)
原文:https://github.com/chyingp/nodejs-learning-guide 自己敲代码: ClientRequest概览 当你调用 http.request(options ...
- rescan-scsi-bus.sh linux扫盘 脚本
[root@ftp:/home/tools/shell] > yum install sg3_utils* Loaded plugins: fastestmirror Repository ba ...
- Linux 和 Windows 双系统时间同步问题 修改注册表
路径:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation 1:新建 >> DWORD(32 b ...
- mycat读写分离+垂直切分+水平切分+er分片+全局表 测试
原文http://blog.163.com/bigoceanwu@126/blog/static/172718064201683031639683/ 读写分离:利用最基础的mysql主从复制,事务性的 ...
- iview中单击行,使得checkbox状态的方法
直接贴代码,这是一组jquery全选,全不选,反选代码 <!DOCTYPE html> <html lang="en"> <head> < ...
- HDU 4069 数独
好久没做题了,建图搞了好久…… 然后,判是否有多解的时候会把原来的答案覆盖掉…… 这里没注意,弄了一下午…… 代码: #include <iostream> #include <cs ...
- 使用JNA,让java调用原生代码
JNA定义: JNA:java Native Access,是SUN公司开发的基于JNI的框架.JNI使得Java可以调用原生的c或者c++代码. JNA与JNI(Java Native Interf ...