poj 1259 Agri-Net(最小生成树)
题目:http://poj.org/problem?id=1258
题意:模板题 和2485差不多 就是求相连后的最小值。
#include <iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
using namespace std;
int bin[];
struct node
{
int u,v,w;
} q[];
bool cmp(node x,node y)
{
return x.w<y.w;
}
int find(int a)
{
if(a==bin[a])
return a;
else
bin[a]=find(bin[a]);
}
int main()
{
int i,j,n,num,p,m;
int x,y;
int sum;
while(~scanf("%d",&n))
{
num=; m=n*n; sum=;
for(i=; i<=n; i++)
bin[i]=i;
p=;
for(i=; i<=n; i++)
for(j=; j<=n; j++)
{
q[p].u=i; q[p].v=j;
scanf("%d",&q[p].w);
p++;
}
sort(q,q+m,cmp);
for(i=; i<m; i++)
{
x=find(q[i].u);
y=find(q[i].v);
if(x!=y)
{
sum+=q[i].w;
num++;
bin[x]=y;
}
if(num==n-)
{
break;
}
}
cout<<sum<<endl;
}
}
poj 1259 Agri-Net(最小生成树)的更多相关文章
- POJ 2485 Highways【最小生成树最大权——简单模板】
链接: http://poj.org/problem?id=2485 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...
- poj 1251 Jungle Roads (最小生成树)
poj 1251 Jungle Roads (最小生成树) Link: http://poj.org/problem?id=1251 Jungle Roads Time Limit: 1000 ...
- POJ 2349 Arctic Network (最小生成树)
Arctic Network Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Subm ...
- POJ 1751 Highways (最小生成树)
Highways 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/G Description The island nation ...
- poj 3026 Borg Maze (最小生成树+bfs)
有几个错误,调试了几个小时,样例过后 1Y. 题目:http://poj.org/problem?id=3026 题意:就是让求A们和S的最小生成树 先用bfs找每两点的距离,再建树.没剪枝 63MS ...
- ZOJ 1542 POJ 1861 Network 网络 最小生成树,求最长边,Kruskal算法
题目连接:problemId=542" target="_blank">ZOJ 1542 POJ 1861 Network 网络 Network Time Limi ...
- ●POJ 1259 The Picnic
题链: http://poj.org/problem?id=1259 题解: 计算几何,凸包,DP 题意:给出N($N\leq100$)个点,求出最大的凸包使得凸包里面不存在点(边上可以有).输出最大 ...
- 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 2485 Highways (最小生成树)
链接:poj 2485 题意:输入n个城镇相互之间的距离,输出将n个城镇连通费用最小的方案中修的最长的路的长度 这个也是最小生成树的题,仅仅只是要求的不是最小价值,而是最小生成树中的最大权值.仅仅须要 ...
随机推荐
- Get vertical scrollbar width and example
$.scrollbarWidth = function () { var parent, child, width; if (width === undefined) { parent = $('&l ...
- Js popup position which right under target item
<div style="margin-left:600px;"> <div id="Span1" style="color:#eee ...
- Laravel框架数据库CURD操作、连贯操作总结
这篇文章主要介绍了Laravel框架数据库CURD操作.连贯操作.链式操作总结,本文包含大量数据库操作常用方法,需要的朋友可以参考下 一.Selects 检索表中的所有行 复制代码代码如下: $use ...
- foxtable使用笔记
1.设置关联表窗口的列的顺序:Tables("award.people").SetColVisibleWidth("name|100|sex|100|job|100|ag ...
- iomanip,setw(),setw: undeclared identifier
今天使用setw(),提示setw: undeclared identifier,上网查了下,原来是没有包含头文件iomanip,现摘录如下: iomanip #include <iomanip ...
- Button控件
1.通过设置AutoSize(bool)属性来控制按钮的大小以适应文本的长度 btn_One.AutoSize = true;//设置按钮基于内容自动调整大小 2.当按钮得到焦点是自动放大,失去焦点时 ...
- HDU 3487 Splay
给定两种操作,一种是把一个数列的某一段切下来插到剩余数列的某一个位置上. 一种是翻转操作,把数列的某一段进行翻转. 都是Splay的基本操作.标准的Rotateto调整出 [a,b]区间.然后对[a, ...
- OO之装饰者模式
以下为装饰者模式详解: 引子: 假如有一个快餐店,基本种类分为米饭,水饺,粉面等,但每一种类型的快餐又可以搭配不同的料,如米饭可以点各种不同的菜(排骨,青菜,土豆等),如果按照一般的设计,快餐为基类, ...
- linux常用命令及安装软件命令
1.查看操作系统是33位还是64最简单的方法 getconf LONG_BIT 或者 uname -a 2.常用命令 2.1基本操作 clear 清屏 2.2安装命令 rpm(redhat packa ...
- unity3d引擎程序员养成
标准流程:1. c++ Primer 英文版(第四或第五版)全部看完习题做完是必须的.渲染程序设计比较复杂,后期会用到c++的全部特性.c++学的越好后面越轻松.要看英文版,计算机翻来覆去就那么几个单 ...