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 ...
随机推荐
- POJ 2431 Expedition (priority_queue或者multiset可解)
Expedition Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18655 Accepted: 5405 Descr ...
- <%=%>、<%%>、<%@%>、<%#%>的区别
1.<%= %> 里面放变量名,获取后台的变量值,直接输入变量到页面上,里面放的变量名,未经过encode eg: 后台: seession["ab"]=ab; 前台: ...
- jquery 几种类选择器方式
代码如下: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestClas ...
- shell-3.bash的基本功能: history tab alias 快捷键
- 路飞学城Python-Day5
48.字典的类型的详细方法字典的增加值dic["k1"] = "v1"字典的修改dic["k2"] = "v2"判断是否 ...
- C# treeview绑定
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) ...
- GUI 图形用户界面 [学习笔记]
今晚返璞归真了一把, 系统了解了一下GUI的有关知识: GUI(Graphical User Interface) 图形用户界面 是指采用图形方式显示的计算机操作用户接口.与早期计算机使用的命令行界面 ...
- Python3+Gurobi使用教程(一)
Gurobi使用教程 1.Gurobi使用的一般框架 from gurobipy import * try: m=Model('modelname') except GurobiError: prin ...
- ASP.NET-使用事件监视诊断程序异常
用windows自带的事件监视程序来监视网站的异常 来自为知笔记(Wiz)
- Atitit.html解析器的选型 jsoup nsoup ,java c# .net 版本号
Atitit.html解析器的选型 jsoup nsoup ,java c# .net 版本号 1. 框架选型的要求 1 1.1. 文档多 1 1.2. 跨平台 1 2. html解析器特性: 1 2 ...