#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的更多相关文章

  1. Agri-Net - poj 1258 (Prim 算法)

      Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 44373   Accepted: 18127 Description F ...

  2. 最小生成树 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 // 顶点的最大个数 ( ...

  3. 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 ...

  4. POJ 1258 Agri-Net|| POJ 2485 Highways MST

    POJ 1258 Agri-Net http://poj.org/problem?id=1258 水题. 题目就是让你求MST,连矩阵都给你了. prim版 #include<cstdio> ...

  5. Prim算法求权数和,POJ(1258)

    题目链接:http://poj.org/problem?id=1258 解题报告: #include <iostream> #include <stdio.h> #includ ...

  6. POJ 1258 Agri-Net(Prim)

    题目网址:http://poj.org/problem?id=1258 题目: Agri-Net Time Limit: 1000MS   Memory Limit: 10000K Total Sub ...

  7. POJ 1258 Agri-Net(Prim算法求解MST)

    题目链接: http://poj.org/problem?id=1258 Description Farmer John has been elected mayor of his town! One ...

  8. POJ 1258 Agri-Net(最小生成树 Prim+Kruskal)

    题目链接: 传送门 Agri-Net Time Limit: 1000MS     Memory Limit: 10000K Description Farmer John has been elec ...

  9. POJ 1258 Agri-Net(Prim)

    ( ̄▽ ̄)" #include<iostream> #include<cstdio> #include<cmath> #include<algori ...

随机推荐

  1. POP and IMAP - Post Office Protocol and Internet Message Access Protocol

    POP and IMAP - Post Office Protocol and Internet Message Access Protocol 用来从 SMTP Server 上下载邮件的协议. P ...

  2. 单线程的REDIS为什么这么快?

    REDIS是单线程处理所有请求,和一般经典实际上推荐的方式相反,那么单线程串行处理,为什么依然能够做到很快呢?知乎上的一个答案如下,其中线程切换和锁不是性能主要影响因素的观点和一般的答案都不同: 作者 ...

  3. 和内嵌的iframe进行通讯

    利用内置iframe进行通讯 1. 在当前网页设置iframe网页(监听iframe发来postmessage消息事件) a. 外部网页接收数据: 回调方法,其中e.data为传入数据: const ...

  4. 【python-leetcode206-翻转链表】反转链表

    问题描述: 反转一个单链表. 示例: 输入: 1->2->3->4->5->NULL输出: 5->4->3->2->1->NULL进阶:你可 ...

  5. 让div充满整个body

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. Mysql无法启动、闪退

    一.mysql下载完成后,运行bin目录下的mysql.exe,提示文件缺失   二.此报错为VC运行库不全或没有安装导致,百度搜索“微软常用运行库合集”进行下载安装即可解决   三.运行时闪退,无法 ...

  7. JS中new的实现原理及重写

    提到new,肯定会和类和实例联系起来,如: function Func() { let x = 100; this.num = x + } let f = new Func(); 上面的代码,我们首先 ...

  8. 区间操作---树状数组&&线段树

    涉及区间操作的一些套路必须要会呀 区间加减为了偷懒能不写线段树so我选择树状数组!! 但是区间乘除,最大值我想了想还是用线段树分块吧. 树状数组: 这里用网上的一张图: 这里灰色数组是原本的数组(a[ ...

  9. 安全师(网络安全类pdf电子书籍)

    2020-02-17  天气晴,西安. 今天找到一个可以下载网络安全(渗透,kali,web)电子书籍网站. https://www.secshi.com/

  10. C# monitor keyboard and mouse actions based on MouseKeyHook.

    1.Install-package MouseKeyHook 2. using Gma.System.MouseKeyHook; using System; namespace ConsoleApp1 ...