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. 厂商自定义USB设备固件程序及特性

    通过前面的学习,大家应该对USB固件程序结构有了比较深的认识,现在再来详细说说固件里决定设备识别成厂商自定义USB设备的地方有哪些,或者说厂商自定义USB设备的固件特性有哪些. 之前不止一次说过学习U ...

  2. hdu 1715 大菲波数_java

    用java的大数解决 import java.math.BigInteger; import java.util.Scanner; public class Main { public static ...

  3. #include <stack>

    1 pop(); 出栈 2 push(); 入栈 3 size(); 返回栈中元素个数 4 top(); 返回栈顶元素 使用栈,把十进制转换为二进制 #include <iostream> ...

  4. OAuth2.0服务器端的实现

    authorize 授权关系存储表字段 备注appid 应用IDuserid 用户IDaddtime 添加时间…… 其他表3 access_token 访问令牌存储表字段 备注access_token ...

  5. 每个人应该知道的NVelocity用法

    NVelocity是一个基于.NET的模板引擎(template engine).它允许任何人仅仅简单的使用模板语言(template language)来引用由.NET代码定义的对象.从而使得界面设 ...

  6. C# DropDownList绑定文件夹

    首先创建一个类,类名称为FileControl, /// <summary> /// 获取制定文件夹下面的文件夹 /// </summary> /// <param na ...

  7. SET STATISTICS IO和SET STATISTICS TIME 在SQL Server查询性能优化中的作用

    近段时间以来,一直在探究SQL Server查询性能的问题,当然也漫无目的的查找了很多资料,也从网上的大神们的文章中学到了很多,在这里,向各位大神致敬.正是受大神们无私奉献精神的影响,所以小弟也作为回 ...

  8. .net 生成缩略图

    public static void CreateSmallImage(string minImageFullPath, System.Drawing.Image originalImage, int ...

  9. js、jquery、css使用过程中学到的一些方法技巧

    快速查看 1 动态创建script/link/style标签 2 在不适合使用iframe的情况下,让页面像iframe那样能分块滚动 3  鼠标在元素上时显示tip风格的提示信息 1.动态创建scr ...

  10. ES6笔记① var 和 let的区别

    let 和 var的区别    答:不同点在于作用域 1.(全局下)首先  let关键字声明的变量是这样写会导致错误. let声明的变量类似于”本地变量“,函数内如何不重新声明,还是会被改变 var ...