POJ1861 Network
| Time Limit: 1000MS | Memory Limit: 30000KB | 64bit IO Format: %lld & %llu |
Description
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
Output
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
/*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的更多相关文章
- POJ1861 Network(Kruskal)(并查集)
Network Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 16047 Accepted: 6362 Spec ...
- POJ-1861,Network,最小生成树水题,,注意题面输出有问题,不必理会~~
Network Time Limit: 1000MS Memory Limit: 30000K Special Judge http://poj.org/problem?id=1 ...
- POJ1861 Network (Kruskal算法 +并查集)
Network Description Andrew is working as system administrator and is planning to establish a new net ...
- 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个点 ...
- poj1861 network(并查集+kruskal最小生成树
题目地址:http://poj.org/problem?id=1861 题意:输入点数n和边数n,m组边(点a,点b,a到b的权值).要求单条边权值的最大值最小,其他无所谓(所以多解:(.输出单条边最 ...
- 最小生成树练习1(克鲁斯卡尔算法Kruskal)
今天刷一下水题练手入门,明天继续. poj1861 Network(最小生成树)新手入门题. 题意:输出连接方案中最长的单根网线长度(必须使这个值是所有方案中最小的),然后输出方案. 题解:本题没有直 ...
- Recurrent Neural Network系列1--RNN(循环神经网络)概述
作者:zhbzz2007 出处:http://www.cnblogs.com/zhbzz2007 欢迎转载,也请保留这段声明.谢谢! 本文翻译自 RECURRENT NEURAL NETWORKS T ...
- 创建 OVS flat network - 每天5分钟玩转 OpenStack(134)
上一节完成了 flat 的配置工作,今天创建 OVS flat network.Admin -> Networks,点击 "Create Network" 按钮. 显示创建页 ...
- 在 ML2 中配置 OVS flat network - 每天5分钟玩转 OpenStack(133)
前面讨论了 OVS local network,今天开始学习 flat network. flat network 是不带 tag 的网络,宿主机的物理网卡通过网桥与 flat network 连接, ...
随机推荐
- kvc to nsdata
[NSKeyedArchiver archivedDataWithRootObject:arr]; [NSKeyedUnarchiver unarchiveObjectWithData: ...
- Encryption-基础:MD5加密
环境:vc2003 .h /* MD5.H - header file for MD5C.C */ /* Copyright (C) 1991-2, RSA Data Security, Inc. C ...
- 自己开发一个APP需要多少钱
广州APP开发公司[启汇网络]经常遇到有开发定制APP软件需求的企业,通常第一句问的就是“开发一款APP需要多少钱”,在做完客户行业的市场调查后,再了解客... 广州APP开发公司[启汇网络]经常遇到 ...
- null 理解
值 null 特指对象的值未设置.它是 JavaScript 基本类型 之一. 语法节 null 描述节 值 null 是一个字面量,它不像undefined 是全局对象的一个属性.null 是表示缺 ...
- 响应式Web设计- 图片
使用width属性:如果width属性设置为100%,图片会根据上下范围实现响应式的功能. <!DOCTYPE html><html><head><meta ...
- Mac屏幕亮度保存
关于保存屏幕亮度的方法,论坛上已有几种,搜索 NVRAM 会出来很多教程,在此不再详述,可以参考帖子http://www.idelta.info/archives/nvram_on_hackintos ...
- MariaDB数据库(五)
1. MariaDB主从架构 1.1 概述 主从架构用来预防数据丢失.主从多用于网站架构,因为主从的同步机制是异步的,数据的同步有一定延迟,也就是说有可能会造成数据的丢失,但是性能比较好,因此网站大多 ...
- Linux基础学习-数据备份工具Rsync
数据备份工具rsync 作为一个系统管理员,数据备份是非常重要的,如果没有做好备份策略,磁盘损坏了,那么你的数据将全部丢失,所以在日常的维护工作中,一定要时刻牢记给数据做备份. rsync不仅可以可以 ...
- 绑定用户id,用户权限认证
上面这个就是为了把user_id与文章关联起来 文章需要跟用户关联,所以要去文章模型中加以关联 这样就可以直接在模板中进行关联处理 权限认证 首先要创建policy php artisan make: ...
- 剑指Offer(书):树的子结构
题目:输入两棵二叉树A,B,判断B是不是A的子结构.(ps:我们约定空树不是任意一个树的子结构) 分析:关于二叉树大部分适应于递归结构. public boolean HasSubtree(TreeN ...