Agri-Net POJ - 1258 prim
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=;
#define inf 1<<29
int map[N][N],n;
int dist[N];
bool st[N];
void prim(){
memset(dist,0x3f,sizeof dist);
memset(st,,sizeof st);
int res=;
for(int i=;i<=n;i++)
{
int t=-;
for(int j=;j<=n;j++)
if(!st[j]&&(t==-||dist[t]>dist[j]))
t=j;
if(i!=)
res+=dist[t];
st[t]=true;
for(int j=;j<=n;j++)
dist[j]=min(dist[j],map[t][j]);
}
cout<<res<<endl;
} int main(){
while(cin>>n&&n){
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
cin>>map[i][j];
prim();
}
return ;
}
Agri-Net POJ - 1258 prim的更多相关文章
- Agri-Net - poj 1258 (Prim 算法)
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 44373 Accepted: 18127 Description F ...
- 最小生成树 10.1.5.253 1505 poj 1258 http://poj.org/problem?id=1258
#include <iostream>// poj 1258 10.1.5.253 1505 using namespace std; #define N 105 // 顶点的最大个数 ( ...
- 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 1258 Agri-Net|| POJ 2485 Highways MST
POJ 1258 Agri-Net http://poj.org/problem?id=1258 水题. 题目就是让你求MST,连矩阵都给你了. prim版 #include<cstdio> ...
- Prim算法求权数和,POJ(1258)
题目链接:http://poj.org/problem?id=1258 解题报告: #include <iostream> #include <stdio.h> #includ ...
- POJ 1258 Agri-Net(Prim)
题目网址:http://poj.org/problem?id=1258 题目: Agri-Net Time Limit: 1000MS Memory Limit: 10000K Total Sub ...
- POJ 1258 Agri-Net(Prim算法求解MST)
题目链接: http://poj.org/problem?id=1258 Description Farmer John has been elected mayor of his town! One ...
- POJ 1258 Agri-Net(最小生成树 Prim+Kruskal)
题目链接: 传送门 Agri-Net Time Limit: 1000MS Memory Limit: 10000K Description Farmer John has been elec ...
- POJ 1258 Agri-Net(Prim)
( ̄▽ ̄)" #include<iostream> #include<cstdio> #include<cmath> #include<algori ...
随机推荐
- [redis读书笔记] 第一部分 数据结构与对象 字典
三 字典 字典是Hash对象的底层实现,比如用HSET创建一个HASH的对象,底层可能就是用一个字典实现的键值对. 字典的实现主要设计下面三个结构: /* * 哈希表节点 */ typedef str ...
- Linux bash管道符“|”使用介绍与例子
https://blog.csdn.net/wangqianyilynn/article/details/75576815
- Centos 7 主要命令改动 service chkconfig iptables
1.service.chkconfig => systemctl seivice和chkconfig 是linux上的常用命令在centos7上被systemctl代替. CentOS 7 使用 ...
- 一步步搭建jumpserver
测试推荐环境 CPU: 64位双核处理器 内存: 4G DDR3 数据库:mysql 版本大于等于 5.6 mariadb 版本大于等于 5.5.6 环境 系统: CentOS 7 IP: 192.1 ...
- centos6.5安装openLDAP2.3
查看系统版本,内核,定时任务同步时间,关闭防火墙selinux等 [root@ldap-master ~]# cat /etc/redhat-release CentOS release 6.5 (F ...
- centos6.5下编译安装单实例MySQL5.1
MySQL5.1版本安装3步曲: 1) ./config 指定编译安装参数 2) make 3) make install 查看系统版本号 [root@meinv01 ~]# cat /etc/red ...
- 在Windows系统中安装Redis和php_redis扩展
安装Redis (1)下载redis压缩包,git下载地址https://github.com/MSOpenTech/redis/releases 解压文件夹,在文件夹中运行cmd命令: 输入: ...
- 函数式编程/lambda表达式入门
函数式编程/lambda表达式入门 本篇主要讲解 lambda表达式的入门,涉及为什么使用函数式编程,以及jdk8提供的函数式接口 和 接口的默认方法 等等 1.什么是命令式编程 命令式编程就是我们去 ...
- JS获取最近三个月日期范围
function getLast3Month() { var now = new Date(); var year = now.getFullYear(); var month = now.getMo ...
- [dubbo 源码之 ]1. 服务提供方如何发布服务
服务发布 启动流程 1.ServiceConfig#export 服务提供方在启动部署时,dubbo会调用ServiceConfig#export来激活服务发布流程,如下所示: Java API: ` ...