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 ...
随机推荐
- Android中使用HttpGet和HttpPost访问HTTP资源
需求:用户登录(name:用户名,pwd:密码) (一)HttpGet :doGet()方法//doGet():将参数的键值对附加在url后面来传递 public String getResultFo ...
- 怎样找Android里自带的数据库?
首先先让它显示出来. 窗口window下的Show View 下的File Explorer(other里), 这时File Explorer窗口 就会显示出来,下一步我们找到data下的data,然 ...
- 模板-->欧几里得算法
如果有相应的OJ题目,欢迎同学们提供相应的链接 相关链接 所有模板的快速链接 简单的测试 None 代码模板 /* * TIME complexity:O(logN) means very fast. ...
- js select 实现左右传值.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- POJ 1039 Pipe 枚举线段相交
Pipe Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9493 Accepted: 2877 Description ...
- RxJava 教程-1 简介 原理 线程控制 变换
简介 RxJava 是什么? RxJava 在 GitHub 主页上的自我介绍是 RxJava is a Java VM implementation of ReactiveX: a library ...
- ASP.NET中 分析器错误:发现不明确的匹配
这是一个不好的代码习惯引起的发布后运行时的问题.错误原因为.net2.0无法正确识别服务器控件和变量的大小写区别,但是这个错误只有在iis中体现,在文件系统的调试中没有发生. 错误信息 引发错误的参考 ...
- MySQL user表root用户误删除后恢复
mysql user表root 用户误删除后恢复root用户 方法/步骤 1.停止mysql服务:在mysql安装目录下找到my.ini:在my.ini中找到以下片段[mysqld]:另起一行加入代码 ...
- ORACLE 解析xml字符串-转载的
--------------------------方法一------------------------------------- 1.xml字符串 /* <orderlist> ...
- 【转】那些好用的iOS开发工具
原文:http://www.devtang.com/blog/2014/06/29/ios-dev-tools/ 前言 从苹果发明iPhone起,AppStore上的一个又一个类似flappy bir ...