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 ;
}

最新文章

  1. ios 快速审核
  2. hiho一下 第六十四周 Right-click Context Menu
  3. MOB 短信验证
  4. Unity3D中自带事件函数的执行顺序(转)
  5. MySQL中四舍五入的实现
  6. nginx_tomcat负载均衡环境
  7. 【HDOJ】3832 Earth Hour
  8. jquery之图片上传
  9. SilkTest Q&amp;A 8
  10. HYSBZ 1036(树链剖分)
  11. session与cookie的差别
  12. 转 互联网推送服务原理:长连接+心跳机制(MQTT协议)
  13. Html&lt;img&gt;标签特写 2017-03-10 AM
  14. jQuery与原生js实现banner轮播图
  15. 《JavaScript设计模式与开发实践》知识点笔记
  16. web服务器学习3---httpd 2.4.29日志处理
  17. bootstrap 简单练习(后续把其它页面也进行练习)
  18. Unity手游之路手游代码更新策略探讨
  19. 【POJ1961】最短周期串/最大周期 kmp
  20. mysql存储过程游标嵌套循环

热门文章

  1. ubuntu 14.04 安装mysql,并配置远程连接和中文乱码
  2. 团队作业-Beta冲刺第二天
  3. 1658: Easier Done Than Said?
  4. python常用模块之requests
  5. tableview和searchbar的适配
  6. ios之UISearchBar
  7. MAC的睡眠模式介绍
  8. Re:从零开始的Linux之路(文件权限)
  9. 【java】【转发】classpath、path、JAVA_HOME的作用及JAVA环境变量配置
  10. docker:安装mysql多个