Network()
Network
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 60000/30000K (Java/Other)
Total Submission(s) : 17 Accepted Submission(s) : 8
Special Judge
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 maximum length of a single cable is minimal. There is another problem not each hub can be connected to any other one because of compatibility problems and building geometry limitations. Of course, Andrew will provide you all necessary information about possible hub connections.
You are to help Andrew to find the way to connect hubs so that all above conditions are satisfied.
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define MAX(x,y) (x>y?x:y)
const int MAXN=;
struct Node{
int s,e,c;
};
int cmp(Node a,Node b){
return a.c<b.c;
}
Node dt[MAXN];
int pre[];
int pt[MAXN],k,flot,as;
int find(int x){
return pre[x]= x==pre[x]?x:find(pre[x]);
}
void add(int a,int b){
pt[k++]=a;pt[k++]=b;
}
void initial(){
memset(pre,,sizeof(pre));
k=;flot=;
as=-;
}
void merge(Node a){
int f1,f2;
if(!pre[a.s])pre[a.s]=a.s;
if(!pre[a.e])pre[a.e]=a.e;
f1=find(a.s);f2=find(a.e);
if(f1!=f2){
add(a.s,a.e);
flot++;
as=MAX(as,a.c);
pre[f1]=f2;
}
}
int main(){int N,M;
while(~scanf("%d%d",&N,&M)){
initial();
for(int i=;i<M;i++){
scanf("%d%d%d",&dt[i].s,&dt[i].e,&dt[i].c);
}
sort(dt,dt+M,cmp);
for(int i=;i<M;i++){
merge(dt[i]);
}
printf("%d\n%d\n",as,k/);
for(int i=;i<k;i+=){
printf("%d %d\n",pt[i],pt[i+]);
}
}
return ;
}
Network()的更多相关文章
- [转]VMware虚拟机上网络连接(network type)的三种模式--bridged、host-only、NAT
转自:http://www.cnblogs.com/xiaochaohuashengmi/archive/2011/03/15/1985084.html VMWare提供了三种工作模式,它们是brid ...
- VMware虚拟机上网络连接(network type)的三种模式--bridged、host-only、NAT
VMware虚拟机上网络连接(network type)的三种模式--bridged.host-only.NAT VMWare提供了三种工作模式,它们是bridged(桥接模式).NAT(网络地址转换 ...
- POJ 3659 Cell Phone Network / HUST 1036 Cell Phone Network(最小支配集,树型动态规划,贪心)-动态规划做法
POJ 3659 Cell Phone Network / HUST 1036 Cell Phone Network(最小支配集,树型动态规划,贪心) Description Farmer John ...
- 【POJ 3694】 Network(割边<桥>+LCA)
[POJ 3694] Network(割边+LCA) Network Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 7971 ...
- 更换oracle 集群网卡(Changing a Network Interface)
更换oracle 集群网卡(Changing a Network Interface) 假设换网卡前后 网卡名.ip,网关,子网掩码都不变的话,集群层面不许要做额外的操作. 一下操作为更换网卡后 ...
- Efficient and Accurate Arbitrary-Shaped Text Detection with Pixel Aggregation Network(利用像素聚合网络进行高效准确的任意形状文本检测)
PSENet V2昨日刚出,今天翻译学习一下. 场景文本检测是场景文本阅读系统的重要一步,随着卷积神经网络的快速发展,场景文字检测也取得了巨大的进步.尽管如此,仍存在两个主要挑战,它们阻碍文字检测部署 ...
- ZOJ - 1586 QS Network (Prim)
ZOJ - 1586 QS Network (Prim) #include<iostream> #include<cstring> using namespace std; + ...
- aborb()程序结束形式
abort()与exit()的区别? 分类: MFC 2011-01-04 14:13 2233人阅读 评论(0) ...
- Select()使用否?
David Treadwell ,Windows Socket 的一位开发者,曾经在他的一篇名为"Developing Transport-Independent Applications ...
随机推荐
- haproxy hdr和path
path : string This extracts the request's URL path, which starts at the first slash and ends before ...
- Java面试题之九
四十六.Math.round(11.5)等於多少? Math.round(-11.5)等於多少? 对于这个题,只要弄清楚Math提供的三个与取整相关的方法就OK了. 1.ceil,英文含义是天花板,该 ...
- java/struts/Servlet文件下载与ftp文件上传下载
1.前端代码 使用超链接到Struts的Action或Servlet <a target="_blank" href="ftpFileAction!download ...
- sort(水题)
sort Time Limit: 6000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- cocos2d-x 3.0游戏实例学习笔记《卡牌塔防》第七步---英雄要升级&属性--解析csv配置文件
/* 说明: **1.本次游戏实例是<cocos2d-x游戏开发之旅>上的最后一个游戏,这里用3.0重写并做下笔记 **2.我也问过木头本人啦.他说:随便写,第一别全然照搬代码:第二能够说 ...
- 【最小费用最大流模板】【Uva10806+Spring Team PK】Dijkstra, Dijkstra,
题意:从1到n 再从n到1 不经过重复的边 ,(如果是点就是旅行商问题了),问最短路 建立一个超级源S S到1连一条费用为0,容量为2的边,求费用流即可 如果流<2 那么hehe 否则 输 ...
- HTML5添加背景音乐
html5 audio 给博客 网页加背景音乐 可以加上个按钮或者链接 让其可停止或暂停 下面代码只是暂停 可以弄成暂停 播放两种状态切换.. 可以考虑换成a标签 <a href="# ...
- CentOS用gparted实现无损调整磁盘分区大小
作者: sheldon 测试服务器硬盘挂载在/usr下的分区大小只有10G,随着必须软件都安装在这个目录下,这个分区已经满额,给分区扩容刻不容缓,window下有PQ分区工具,Linux下也有gpar ...
- z-index解决弹出层遮罩层覆盖子div不能显示输出的问题
// 添加以下代码来进行测试: // ajax 发生错误,就会执行$('body').ajaxError(function(e, xhr, setting, text){ // e - even ...
- Google Map 根据坐标 获取地址信息
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.X ...