#include <iostream>//    poj 1258         10.1.5.253   1505
using namespace std;
#define N 105 // 顶点的最大个数 (多写
int a[N][N],low[N],n,ans;
int min(int x,int y)
{ return x<y?x:y; } void prim(int u0)
{
int i,j,m,k;
ans=0; //
for (i=1;i<n;i++)
low[i]=a[u0][i]; //
low[u0]=-1;
for (i=1;i<n;i++) //循环n-1次 依次加入n-1个顶点
{
m=1<<20;
for (j=0;j<n;j++) //找一个最小的的边
if (low[j]!=-1&&low[j]<m)
{ m=low[j]; k=j; }
ans+=m; //
low[k]=-1;
for (j=0;j<n;j++) //
if (low[j]!=-1)
low[j]=min(low[j],a[k][j]);
}
} int main()
{
int i,j;
while(cin>>n&&n>=3)
{
for (i=0;i<n;i++) //邻接矩阵
for (j=0;j<n;j++)
cin>>a[i][j];
prim(0); // 从0开始
cout<<ans<<endl;
}
return 0;
}

  

最小生成树 10.1.5.253 1505 poj 1258 http://poj.org/problem?id=1258的更多相关文章

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

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

  2. BFS 10.1.5.253 1502

    http://10.1.5.253/acmhome/problemdetail.do?&method=showdetail&id=1502 //1502 #include <st ...

  3. poj 1651 http://poj.org/problem?id=1651

      http://poj.org/problem?id=1651Multiplication Puzzle   Time Limit: 1000MS   Memory Limit: 65536K To ...

  4. poj 1679 http://poj.org/problem?id=1679

    http://poj.org/problem?id=1679 The Unique MST Time Limit: 1000MS   Memory Limit: 10000K Total Submis ...

  5. OpenJudge/Poj 1207 The 3n + 1 problem

    1.链接地址: http://bailian.openjudge.cn/practice/1207/ http://poj.org/problem?id=1207 2.题目: 总时间限制: 1000m ...

  6. POJ 1201 Intervals || POJ 1716 Integer Intervals 差分约束

    POJ 1201 http://poj.org/problem?id=1201 题目大意: 有一个序列,题目用n个整数组合 [ai,bi,ci]来描述它,[ai,bi,ci]表示在该序列中处于[ai, ...

  7. poj-3056 http://poj.org/problem?id=3056

    http://poj.org/problem?id=3056 The Bavarian Beer Party Time Limit: 6000MS   Memory Limit: 65536K Tot ...

  8. POJ3278http://poj.org/problem?id=3278

    http://poj.org/problem?id=3278 题目大意: m,n两个数m可+1, -1, *2变成n,需要经过几步 #include<stdio.h> #include&l ...

  9. POJ 3320 Jessica‘s Reading Problem(哈希、尺取法)

    http://poj.org/problem?id=3320 题意:给出一串数字,要求包含所有数字的最短长度. 思路: 哈希一直不是很会用,这道题也是参考了别人的代码,想了很久. #include&l ...

随机推荐

  1. Sql server 数据库中,纯SQL语句查询、执行 单引号问题。

    在默认值情况下, select 'abc',Titile from tb_Name;  ---输出内容 是abc: 如果想输出 单引号 'abc,需要使用select '''abc',Titile f ...

  2. 文字排版--字号、颜色(font-size, color)

    可以使用下面代码设置网页中文字的字号为12像素,并把字体颜色设置为#666(灰色): body{font-size:12px;color:#666} 示例: <!DOCTYPE HTML> ...

  3. Spring+AOP+Log4j 用注解的方式记录指定某个方法的日志

    一.spring aop execution表达式说明 在使用spring框架配置AOP的时候,不管是通过XML配置文件还是注解的方式都需要定义pointcut"切入点" 例如定义 ...

  4. 330. Patching Array--Avota

    问题描述: Given a sorted positive integer array nums and an integer n, add/patch elements to the array s ...

  5. vs 2013 编译zlib

    zlib下载地址: http://pan.baidu.com/s/1pJqTcoV \zlib-1.2.8\contrib\vstudio\vc10\zlibvc.sln 打开这个文件, 根据提示, ...

  6. SGU 168.Matrix

    时间限制:0.5s 空间限制:15M 题意: 给出一个N*M的矩阵A,计算矩阵B,满足B[i][j]=min{ A[x][y]:(y>=j) and ( x>=i+j-y )} Solut ...

  7. Codeforces 527E Data Center Drama(欧拉回路)

    题意: 给定一个无向图连通图,把这个的无向边变成有向边,并添加最少的有向边使这个图每个结点的出度为偶数. Solution: 题目很长,并且很多条件说的不太直接,确实不太好懂. 首先先看得到的无向图, ...

  8. javascript——浅谈javascript模版(自定义)

    /** * Created by Administrator on 15-1-19. */ function functionUtil() { } functionUtil = { //某个DOM节点 ...

  9. javascript——闭包

    <script type="text/javascript"> //什么是闭包: //是指语法域位于某个特定的区域,具有持续参照(读写)位于该区域内自身范围之外的执行域 ...

  10. Ubuntu14.04安装AMD显卡驱动双屏显示器完全解决方案

    网上有很多方法,但是针对AMD显卡的方案不多,所以笔者今天想写一篇关于AMD显卡的教程. 首先,进入这个网址下载一些东东:http://support.amd.com/zh-cn/download/d ...