Network

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 60000/30000K (Java/Other)
Total Submission(s) : 17   Accepted Submission(s) : 8
Special Judge
Problem Description
Andrew 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 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.
 
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 length required to connect them. Length is a positive integer number that does not exceed 106. There will be no more than one way to connect two hubs. A hub cannot be connected to itself. There will always be at least one way to connect all hubs.
 
Output
Output first the maximum length of a single cable in your hub connection plan (the value you should minimize). Then output your plan: first output P - the number of cables used, then output P pairs of integer numbers - numbers of hubs connected by the corresponding cable. Separate numbers by spaces and/or line breaks.
 
Sample Input
4 6 1 2 1 1 3 1 1 4 2 2 3 1 3 4 1 2 4 1
 
Sample Output
1 4 1 2 1 3 2 3 3 4
 题解:
一:找最小生成树的最小权值;
二:生成这个数的数据组数;
三:输出这些数据;
这题样例是错的,无语;
代码:
 #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()的更多相关文章

  1. [转]VMware虚拟机上网络连接(network type)的三种模式--bridged、host-only、NAT

    转自:http://www.cnblogs.com/xiaochaohuashengmi/archive/2011/03/15/1985084.html VMWare提供了三种工作模式,它们是brid ...

  2. VMware虚拟机上网络连接(network type)的三种模式--bridged、host-only、NAT

    VMware虚拟机上网络连接(network type)的三种模式--bridged.host-only.NAT VMWare提供了三种工作模式,它们是bridged(桥接模式).NAT(网络地址转换 ...

  3. POJ 3659 Cell Phone Network / HUST 1036 Cell Phone Network(最小支配集,树型动态规划,贪心)-动态规划做法

    POJ 3659 Cell Phone Network / HUST 1036 Cell Phone Network(最小支配集,树型动态规划,贪心) Description Farmer John ...

  4. 【POJ 3694】 Network(割边&lt;桥&gt;+LCA)

    [POJ 3694] Network(割边+LCA) Network Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 7971 ...

  5. 更换oracle 集群网卡(Changing a Network Interface)

     更换oracle 集群网卡(Changing a Network Interface) 假设换网卡前后 网卡名.ip,网关,子网掩码都不变的话,集群层面不许要做额外的操作. 一下操作为更换网卡后 ...

  6. Efficient and Accurate Arbitrary-Shaped Text Detection with Pixel Aggregation Network(利用像素聚合网络进行高效准确的任意形状文本检测)

    PSENet V2昨日刚出,今天翻译学习一下. 场景文本检测是场景文本阅读系统的重要一步,随着卷积神经网络的快速发展,场景文字检测也取得了巨大的进步.尽管如此,仍存在两个主要挑战,它们阻碍文字检测部署 ...

  7. ZOJ - 1586 QS Network (Prim)

    ZOJ - 1586 QS Network (Prim) #include<iostream> #include<cstring> using namespace std; + ...

  8. aborb()程序结束形式

    abort()与exit()的区别?         分类:             MFC              2011-01-04 14:13     2233人阅读     评论(0)   ...

  9. Select()使用否?

    David Treadwell ,Windows Socket 的一位开发者,曾经在他的一篇名为"Developing Transport-Independent Applications ...

随机推荐

  1. 打开本地STL文件并创建webgl使用的geometry

    需求 打开本地STL文件 一个独立基于webgl的viewer,会被别的网站重用 将打开文件的数据传输给viewer,并且在文件加载的时候显示进度条 解决方案 #1可以使用传统的html5 api来打 ...

  2. 关于网络协议和socket编程基本概念

    TCP协议可以说已经是IT人耳熟能详的协议,最近在学习socket网络编程时后重新温习一下这个协议,针对一些问题做了一些总结,很多理解可能还不是很准确. 1. 协议是什么?所谓的各种网络协议无非是一种 ...

  3. 2014第7周三初识CouchBase

    今天主要还是完善需求,然后提交评审流程,尽可能不纠结一些细节问题后发现自己速度更快了,或许这才是最好的顺序,其它可能的问题就留在后续发现并解决吧.今天第一次听到并重视下couchbase.上午看到同事 ...

  4. WIN_2003_SP2.iso VMware 不能进行网络访问的处理

    1.打开IE发现不能上网的问题 ping命令 发现确实是网络不通: 2.关闭虚拟机设置网络适配器 3.ping命令验证是否设置成功 4.打开IE访问百度

  5. opendrive.com提供的免费网盘

    opendrive.com是由以前freehao123给大家介绍的BOXSTr免费网络硬盘演变而来的,现在BOXSTr已经无法使用了.打开BOXSTr网站就会自动跳转到opendrive.com网站. ...

  6. PHP单例模式编写

    今天来点基础的设计模式: 如何利用单例模式实现一个数据库中间层 class Db{ static private $_instance; //当前数据库连接实例 static public funct ...

  7. poj 1149 PIGS_网络流

    #include<iostream> #include<queue> #include<cstdio> #include<cstring> using ...

  8. Makefile与Shell的问题

    http://blog.csdn.net/absurd/article/details/636418 Makefile与Shell的问题 大概只要知道Makefile的人,都知道Makefile可以调 ...

  9. C语言课程设计—图书管理系统

    这是本人大一第二学期初C语言课程设计的作品,嘿嘿,本来以为已经找不到原稿了,今天无意中居然在QQ网络硬盘中找到了当初的teta版,公布于此,以作纪念. C源码例如以下: #include<std ...

  10. C++ buffer缓冲区的秘密

    在搞数据库和C++进行连接的时候,遇到一个问题,就是如果前面用到了fflush(stdin)即清空缓冲区,就OK,如果不清空缓冲区就不能把记录加入到Mysql的数据库中, 但是即便如此,这个问题目前还 ...