B - Networking - poj 1287
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<vector>
using namespace std; #define maxn 105 struct node
{
int u, v, len;
friend bool operator < (node a, node b)
{
return a.len > b.len;
}
};
int f[maxn]; int Find(int x)
{
if(f[x] != x)
f[x] = Find(f[x]);
return f[x];
} int main()
{
int N, M; while(scanf("%d", &N) != EOF && N)
{
int i, ans=0;
priority_queue<node>Q;
node s; for(i=0; i<=N; i++)
f[i] = i;
scanf("%d", &M); while(M--)
{
scanf("%d%d%d", &s.u, &s.v, &s.len);
Q.push(s);
} while(Q.size())
{
s = Q.top();Q.pop(); int u = Find(s.u), v = Find(s.v); if(u != v)
{
f[u] = v;
ans += s.len;
}
} printf("%d\n", ans);
} return 0;
}
B - Networking - poj 1287的更多相关文章
- (最小生成树) Networking -- POJ -- 1287
		链接: http://poj.org/problem?id=1287 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7494 ... 
- Networking POJ - 1287
		题目链接:https://vjudge.net/problem/POJ-1287 思路:最小生成树板子题 #include <iostream> #include <cstdio&g ... 
- Networking POJ - 1287   最小生成树板子题
		#include<iostream> #include<algorithm> using namespace std; const int N=1e5; struct edge ... 
- POJ 1287 Networking (最小生成树)
		Networking Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Submit S ... 
- ZOJ1372 POJ 1287 Networking 网络设计 Kruskal算法
		题目链接:problemCode=1372">ZOJ1372 POJ 1287 Networking 网络设计 Networking Time Limit: 2 Seconds ... 
- POJ.1287 Networking (Prim)
		POJ.1287 Networking (Prim) 题意分析 可能有重边,注意选择最小的边. 编号依旧从1开始. 直接跑prim即可. 代码总览 #include <cstdio> #i ... 
- poj 1251 poj 1258 hdu 1863 poj 1287  poj 2421 hdu 1233 最小生成树模板题
		poj 1251 && hdu 1301 Sample Input 9 //n 结点数A 2 B 12 I 25B 3 C 10 H 40 I 8C 2 D 18 G 55D 1 E ... 
- POJ 1287 Networking
		题目链接: poj.org/problem?id=1287 题目大意: 你被分派到去设计一个区域的连接点,给出你每个点对之间的路线,你需要算出连接所有点路线的总长度. 题目输入: 一个数字n 代表有 ... 
- POJ 1287:Networking(最小生成树Kruskal)
		id=1287">Networking Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5976 Acce ... 
随机推荐
- mcrypt.h not found. Please reinstall libmcrypt
			在centos上对php5.6进行源码安装的时候, 出现了如题所示错误提示, 原因是由于centos源不能安装libmcrypt-devel,由于版权的原因没有自带mcrypt的包 解决办法使用php ... 
- 2015 UESTC Winter Training #10【Northeastern Europe 2009】
			2015 UESTC Winter Training #10 Northeastern Europe 2009 最近集训都不在状态啊,嘛,上午一直在练车,比赛时也是刚吃过午饭,状态不好也难免,下次比赛 ... 
- windows服务(Windows Installer问题,错误5:拒绝访问)
			Windows Installer问题,错误5:拒绝访问 shillan,2006-11-03 09:40:38 现象: 使用MSI文件来安装的软件在安装和卸载时系统提示:“不能访问Windows I ... 
- 如何成为一名优秀的web前端工程师(转给自己,共勉)
			来源:王子墨的博客 程序设计之道无远弗届,御晨风而返.———— 杰佛瑞 · 詹姆士 我所遇到的前端程序员分两种: 第一种一直在问:如何学习前端? 第二种总说:前端很简单,就那么一点东西. 我从没有听到 ... 
- JS 通过点击事件动态添加文本框
			直接拷贝到浏览器就能实现 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <htm ... 
- Python 3中bytes和str的分别
			最近把一段py2的代码转换到py3的代码,结果运行到向socket中写数据的代码部分出现了'str' does not support the buffer interface这样一个错误. 一番搜索 ... 
- Linux系统配置成简单的路由器
			一.两个不同网段的子网相互访问或通信 废话不多说了,直接上图,一目了然吧. 按照如图配置,就可以实现两个不同网段的子网相互通信. 二.连接上网的配置: 如果想让这两个子网,不仅可以相互通信,而且还可以 ... 
- Python学习笔记:03语法
			Python 语法 Python语法包括: 模块函数导入 赋值 判断循环语句 模块导入 import somemodule somemodule.somefunc from somemodule im ... 
- c程序代码的内存布局(学好C的基础)
			一个程序本质上都是由 BSS 段.data段.text段三个组成的.这样的概念在当前的计算机程序设计中是很重要的一个基本概念,而且在嵌入式系统的设计中也非常重要,牵涉到嵌入式系统运行时的内存大小分配, ... 
- Python 函数传递list,传递dict   以及*args和**kargs
			函数之间传递list: def show(ll): for i in ll: print(i) show(['chen','hang','wang','yadan']) #============== ... 
