poj1681 Network
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 思路:最小生成树应用,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的更多相关文章
- 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 连接, ...
- OVS local network 连通性分析 - 每天5分钟玩转 OpenStack(132)
前面已经创建了两个 OVS local network,今天详细分析它们之间的连通性. launch 新的 instance "cirros-vm3",网络选择 second_lo ...
- 再部署一个 instance 和 Local Network - 每天5分钟玩转 OpenStack(131)
上一节部署了 cirros-vm1 到 first_local_net,今天我们将再部署 cirros-vm2 到同一网络,并创建 second_local_net. 连接第二个 instance 到 ...
- 创建 OVS Local Network - 每天5分钟玩转 OpenStack(129)
上一节我们完成了 OVS 的准备工作,本节从最基础的 local network 开始学习.local network 不会与宿主机的任何物理网卡连接,流量只被限制在宿主机内,同时也不关联任何的 VL ...
- 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 ...
- BZOJ 1146: [CTSC2008]网络管理Network [树上带修改主席树]
1146: [CTSC2008]网络管理Network Time Limit: 50 Sec Memory Limit: 162 MBSubmit: 3522 Solved: 1041[Submi ...
- [Network Analysis] 复杂网络分析总结
在我们的现实生活中,许多复杂系统都可以建模成一种复杂网络进行分析,比如常见的电力网络.航空网络.交通网络.计算机网络以及社交网络等等.复杂网络不仅是一种数据的表现形式,它同样也是一种科学研究的手段.复 ...
随机推荐
- linux的sed命令(一)
转自:https://www.cnblogs.com/ginvip/p/6376049.html Sed 简介 sed 是一种新型的,非交互式的编辑器.它能执行与编辑器 vi 和 ex 相同的编辑任务 ...
- [Android] Android Error: Suspicious namespace and prefix combination [NamespaceTypo] when I try create Signed APK
Error: Suspicious namespace and prefix combination [NamespaceTypo] 解决办法: xmlns:app 的值改为: xmlns:app=& ...
- neufz
~~~~1--1--5--2020/4/23 08:50:30|1--1--5--2020/4/23 08:50:30|1--1--5--2020/4/23 08:50:30|1--1--5--202 ...
- linux常用系统指令
[linux常用系统指令] 查看内核版本:cat /proc/version 查看发行版本:cat /etc/issue 通过安装lsb的方式查看发行版本: yum provides */lsb_re ...
- Python:正则表达式(二):如何使用re.search()返回的匹配对象中的具体内容呢??
在上一篇中讲述了re.seach()会返回一个对象格式的数据,如下:<_sre.SRE_Match object; span=(16, 24), match='${phone}'> 那么问 ...
- Java基础 -- Java 抽象类 抽象方法
总结: 1. 抽象类不能被实例化(初学者很容易犯的错),如果被实例化,就会报错,编译无法通过.只有抽象类的非抽象子类可以创建对象. 2. 抽象类中不一定包含抽象方法,但是有抽象方法的类必定是抽象类. ...
- Maven - 镜像<mirror>
使用镜像如果你的地理位置附近有一个速度更快的central镜像,或者你想覆盖central仓库配置,或者你想为所有POM使用唯一的一个远程仓库(这个远程仓库代理的所有必要的其它仓库),你可以使用set ...
- Java基础12-工具类;变长参数;IO
作业解析 取出整数的16进制表示形式 \u00ff /** * int2hex * */ public static String int2hex(int i) { String str = &quo ...
- python封装configparser模块获取conf.ini值
configparser模块是python自带的从文件中获取固定格式参数的模块,因为是python只带的,大家用的应该很多,我觉得这个参数模块比较灵活,添加参数.修改参数.读取参数等都有对应的参数供用 ...
- NB-IoT有三种部署方式及特点【转】
转自:http://blog.sina.com.cn/s/blog_13ddf053f0102wcbz.html NB-IoT有三种运营模式,一种是独立的在运营商的网络外面重做:第二种是在LTE的保护 ...