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. rhythmbox插件开发笔记2:背景知识学习 D-Bus&VFS&Gio& Python GTK+ 3

    这次主要简单介绍下相关的背景知识 D-Bus&VFS&Gio& Python GTK+ 3  D-Bus D-Bus是开源的进程通信(IPC)系统,它允许多个进程进行实时通信. ...

  2. JNI工程搭建及编译

    JNI工程搭建及编译 建立Java工程 在具有C/C++比编译器的Eclipse中进行工程的创建,先创建一个简单的Java project,选项和一般同,这里仅仅需要将要调用的C/C++函数声明为na ...

  3. leetcode_1095. Find in Mountain Array_[Binary Search]

    https://leetcode.com/problems/find-in-mountain-array/ 题意:给定一个MountainArray(定义见题目),找到其中最早出现的target值的下 ...

  4. hdu 1181 深搜

    中文题 深搜 许久没写鸟,卡在输入问题上... #include <iostream> #include <string> using namespace std; bool ...

  5. selenium+chrome浏览器驱动-爬取百度图片

    百度图片网页中中,当页面滚动到底部,页面会加载新的内容. 我们通过selenium和谷歌浏览器驱动,执行js,是浏览器不断加载页面,通过抓取页面的图片路径来下载图片. from selenium im ...

  6. python基础一 day11 装饰器复习

    # 复习# 讲作业# 装饰器的进阶 # functools.wraps # 带参数的装饰器 # 多个装饰器装饰同一个函数# 周末的作业 # 文件操作 # 字符串处理 # 输入输出 # 流程控制 # 装 ...

  7. Asp.Net Core 进阶(三)—— IServiceCollection依赖注入容器和使用Autofac替换它

    Asp.Net Core 提供了默认的依赖注入容器 IServiceCollection,它是一个轻量级的依赖注入容器,所以功能不多,只是提供了基础的一些功能,要实现AOP就有点麻烦,因此在实际工作当 ...

  8. Python字符编码补充

    字符编码: Python字符编码贯穿Python学习的始终,现在应用的是Python2中字符编码的问题是很多的. 这次是要彻底解决Python字符编码的问题!!! 1 字符编码的发展过程: 1 .AS ...

  9. ZOJ-1360 || POJ-1328——Radar Installation

    ZOJ地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=360 POJ地址:http://poj.org/problem?id ...

  10. bzoj3545 [ONTAK2010]Peaks、bzoj3551 [ONTAK2010]Peaks加强版

    题目描述: bzoj3545,luogu bzoj3551 题解: 重构树+线段树合并. 可以算是板子了吧. 代码(非强制在线): #include<cstdio> #include< ...