Time Limit: 1000MS   Memory Limit: 30000KB   64bit IO Format: %lld & %llu

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 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
3 4

样例输出明显错了。

1

3

1 2

1 3

3 4

这样可行。有Special Judge

Source

Northeastern Europe 2001, Northern Subregion
 
 
裸最小生成树。要求输出生成树中最大边数,连接的点数(肯定是n-1),使用的每条边。
 
 /*by SilverN*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
const int mxn=;
int n,m;
struct node{
int x,y;
int dis;
}e[mxn];
int cnt=;
int cmp(node a,node b){
return a.dis<b.dis;
}
int fa[mxn];
void init(){
for(int i=;i<=n;i++)fa[i]=i;
}
int find(int x){
if(fa[x]==x)return x;
return fa[x]=find(fa[x]);
}
queue<int>aw;
int ans=;
void Kruskal(){
int i,j;
ans=;
int now=;
for(i=;i<=m;i++){
int u=find(e[i].x),v=find(e[i].y);
if(u==v)continue;
aw.push(i);
fa[u]=v;
now++;
ans=max(ans,e[i].dis);
if(now==n-)break;
}
}
int main(){
while(scanf("%d",&n)!=EOF){
init();
int u,v,dis;
m=read();
int i,j;
for(i=;i<=m;i++){
e[i].x=read();e[i].y=read();e[i].dis=read();
}
sort(e+,e+m+,cmp);
Kruskal();
printf("%d\n",ans);
printf("%d\n",n-);
while(!aw.empty()){
int tmp=aw.front();
aw.pop();
printf("%d %d\n",e[tmp].x,e[tmp].y);
}
}
return ;
}

POJ1861 Network的更多相关文章

  1. POJ1861 Network(Kruskal)(并查集)

    Network Time Limit: 1000MS     Memory Limit: 30000K Total Submissions: 16047   Accepted: 6362   Spec ...

  2. POJ-1861,Network,最小生成树水题,,注意题面输出有问题,不必理会~~

    Network Time Limit: 1000MS   Memory Limit: 30000K          Special Judge http://poj.org/problem?id=1 ...

  3. POJ1861 Network (Kruskal算法 +并查集)

    Network Description Andrew is working as system administrator and is planning to establish a new net ...

  4. POJ1861(Network)-Kruskal

    题目在这 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 题目意思:4个点 ...

  5. poj1861 network(并查集+kruskal最小生成树

    题目地址:http://poj.org/problem?id=1861 题意:输入点数n和边数n,m组边(点a,点b,a到b的权值).要求单条边权值的最大值最小,其他无所谓(所以多解:(.输出单条边最 ...

  6. 最小生成树练习1(克鲁斯卡尔算法Kruskal)

    今天刷一下水题练手入门,明天继续. poj1861 Network(最小生成树)新手入门题. 题意:输出连接方案中最长的单根网线长度(必须使这个值是所有方案中最小的),然后输出方案. 题解:本题没有直 ...

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

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

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

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

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

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

随机推荐

  1. 解决activeandroid no such table

    场景:activeandroid拷贝数据库 (1)复制sql数据库到项目的assets目录,例如/myapp/src/main/assets/prepop.db (2)确保manifest的AA_DB ...

  2. 数学题 追及相遇—HDOJ1275 人傻需要多做题

    两车追及或相遇问题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total S ...

  3. caffe实现多label输入(修改源码版)

    http://blog.csdn.net/u013010889/article/details/54614067 这个人的博客本身也相当好

  4. NULL Pointer Dereference(转)

    0x00 漏洞代码 null_dereference.c: #include <linux/init.h> #include <linux/module.h> #include ...

  5. House of Spirit(fastbin)

    0x01 fastbin fastbin所包含chunk的大小为16 Bytes, 24 Bytes, 32 Bytes, … , 80 Bytes.当分配一块较小的内存(mem<=64 Byt ...

  6. (53)zabbix模板

    zabbix模板是做什么的? 平时工作中,我们需要监控web.mysql.redis.nginx这些服务器,众多服务器的业务都是一样的,所以我们只要事先创建好模板,然后所有服务器链接这个模板即可,如果 ...

  7. GIMP图片头发的处理

    1/选中图片,添加Alpha Channel 2/点击Duplicate Layer,复制图层: 3/接着需要调整一下色差,选中Color下的Curves,调节曲线,使背景看起来更白一点 4/选中Co ...

  8. Elementary OS上eclipse卡死问题

    解决: 1.可以用  sudo ./eclipse -vm /home/username/jdk_path/bin/java 启动但是启动后仍有显示问题. 2. 修改 eclipse.ini 在 -- ...

  9. perl:_DATA_ _LINE_ _FILE_

    这三个应该是句柄: _DATA_ _FILE_ _LINE_ 没有找到具体介绍...记录于此,已被后续补充.

  10. shell脚本举例

    1.有时在写一些以循环方式运行的监控脚本,设置时间间隔是必不可少的,下面是一个Shell进度条的脚本演示在脚本中生成延时. #!/bin/bash b='' for ((i=0;$i<=100; ...