题目链接 https://cn.vjudge.net/problem/17712/origin
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 10 6. 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 思路:最小生成树应用,kruskal算法,只要将用过的权值标记出来(例如标记为-1),最后再将其输出就行。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int N = 1e6+10;
int f[N];
struct edge{
int u;
int v;
int cap;
}e[N];
bool cmp(edge x, edge y){
return x.cap < y.cap;
}
int find(int x){
if(x != f[x]){
f[x] = find(f[x]);
}
return f[x];
}
int merge(int u,int v){
int t1 = find(f[u]);
int t2 = find(f[v]);
if(t1 != t2){
f[t2] = t1;
return 1;
}
return 0;
}
int main()
{
int n,m,i,j;
scanf("%d%d",&n,&m);
for(i = 0; i <= n; i++){
f[i] = i;
}
int max = 0,x = 0;
for(i = 1; i <= m; i++){
scanf("%d%d%d",&e[i].u,&e[i].v,&e[i].cap);
}
sort(e+1,e+m+1,cmp);
for(i = 1; i <= m; i++){
if(merge(e[i].u,e[i].v) == 1){
if(e[i].cap > max){
max = e[i].cap;
}
e[i].cap = -1; //标记符合条件的边
x++;
if(x == n-1){
break;
}
}
}
printf("%d\n",max);
printf("%d\n",n-1);
for(i = 1; i <= m; i++){
if(e[i].cap == -1){ //输出符合条件的值
printf("%d %d\n",e[i].u,e[i].v);
}
}
return 0;
}

  


3 4

poj1681 Network的更多相关文章

  1. Recurrent Neural Network系列1--RNN(循环神经网络)概述

    作者:zhbzz2007 出处:http://www.cnblogs.com/zhbzz2007 欢迎转载,也请保留这段声明.谢谢! 本文翻译自 RECURRENT NEURAL NETWORKS T ...

  2. 创建 OVS flat network - 每天5分钟玩转 OpenStack(134)

    上一节完成了 flat 的配置工作,今天创建 OVS flat network.Admin -> Networks,点击 "Create Network" 按钮. 显示创建页 ...

  3. 在 ML2 中配置 OVS flat network - 每天5分钟玩转 OpenStack(133)

    前面讨论了 OVS local network,今天开始学习 flat network. flat network 是不带 tag 的网络,宿主机的物理网卡通过网桥与 flat network 连接, ...

  4. OVS local network 连通性分析 - 每天5分钟玩转 OpenStack(132)

    前面已经创建了两个 OVS local network,今天详细分析它们之间的连通性. launch 新的 instance "cirros-vm3",网络选择 second_lo ...

  5. 再部署一个 instance 和 Local Network - 每天5分钟玩转 OpenStack(131)

    上一节部署了 cirros-vm1 到 first_local_net,今天我们将再部署 cirros-vm2 到同一网络,并创建 second_local_net. 连接第二个 instance 到 ...

  6. 创建 OVS Local Network - 每天5分钟玩转 OpenStack(129)

    上一节我们完成了 OVS 的准备工作,本节从最基础的 local network 开始学习.local network 不会与宿主机的任何物理网卡连接,流量只被限制在宿主机内,同时也不关联任何的 VL ...

  7. Configure a bridged network interface for KVM using RHEL 5.4 or later?

    environment Red Hat Enterprise Linux 5.4 or later Red Hat Enterprise Linux 6.0 or later KVM virtual ...

  8. BZOJ 1146: [CTSC2008]网络管理Network [树上带修改主席树]

    1146: [CTSC2008]网络管理Network Time Limit: 50 Sec  Memory Limit: 162 MBSubmit: 3522  Solved: 1041[Submi ...

  9. [Network Analysis] 复杂网络分析总结

    在我们的现实生活中,许多复杂系统都可以建模成一种复杂网络进行分析,比如常见的电力网络.航空网络.交通网络.计算机网络以及社交网络等等.复杂网络不仅是一种数据的表现形式,它同样也是一种科学研究的手段.复 ...

随机推荐

  1. 【JS】前端文件下载(无刷新)方法总结

    #传统方法 利用iframe 或 form.submit 或 windows.open直接向后端发请求,后端返回文件流,后端处理成功后会直接返回到页面,浏览器会整理并打开自己的保存下载文件机制 . 1 ...

  2. ConcurrentHashMap扩容

    然后,说说精华的部分. Cmap 支持并发扩容,实现方式是,将表拆分,让每个线程处理自己的区间.如下图:     假设总长度是 64 ,每个线程可以分到 16 个桶,各自处理,不会互相影响. 而每个线 ...

  3. ArcGis——好好的属性表,咋就乱码了呢?

    我就瞎说一下,反正你也不懂. ——见到许多ArcGis属性表乱码的问题,也见过各种哭笑不得的解说 目录 第一节 字符编码那些事儿→字符编码简述 第二节 都是编码惹的祸→ArcGis属性表出错原因 第三 ...

  4. Oracle DB 总结(SQL)

    --SQL结构查询语言 数据库定义语言(DDL)用于建立.删除和修改数据库对象 CREATE ALTER DROP TRUNCATE 数据库操纵语言(DML)用于改变数据库表中的数据 INSERT U ...

  5. linux学习------磁盘性能测试

    测试服务器  1核1G配置 下载后放在你想测试的目录下,执行preparefile.sh准备测试文件,完成后执行runTest.sh执行测试,等待测试结果完成. {sysbench_bin}> ...

  6. thinkphp5+vue+iview商城 公众号+小程序更新版本

    thinkphp5+vue+iview商城加分销 源码下载地址:http://github.crmeb.net/u/crmeb 演示站后台:http://demo25.crmeb.net 账号:dem ...

  7. 浅入深出Vue:环境搭建

    浅入深出Vue:环境搭建 工欲善其事必先利其器,该搭建我们的环境了. 安装NPM 所有工具的下载地址都可以在导航篇中找到,这里我们下载的是最新版本的NodeJS Windows安装程序 下载下来后,直 ...

  8. Socket netty ...

    1.什么是Socket? Socket就是为网络服务提供的一种机制. 通讯的两端都有Sokcet 网络通讯其实就是Sokcet间的通讯 数据在两个Sokcet间通过IO传输. 2.TCP与UDP在概念 ...

  9. 入坑DL CV 一些基础技能学习

    进入实验室学习了一个月左右,记录一下新手入门所学的基本知识,都是入门级别的教程 1.Python 快速入门:廖雪峰Python教程--> https://www.liaoxuefeng.com/ ...

  10. CF1153D Serval and Rooted Tree

    题目地址:CF1153D Serval and Rooted Tree 挺好玩儿也挺考思维的一道题 思路:树形DP+贪心 数组 \(d\) 维护这样一个值: 对于一个节点 \(x\) ,它的值最大可以 ...