1102 Constructing Roads
来源:互联网 发布:推荐几个精仿的淘宝店 编辑:程序博客网 时间:2024/06/11 19:31
最小生成树 Prim算法
#include<iostream>using namespace std;#define max 101#define MAX10000000int len[max][max];int que[max];int n;int Prim(){int i,j;int sum=0;int lea[max];int k;int min;for(i=1;i<=n;i++)lea[i]=len[1][i];que[1]=1;for(i=2;i<=n;i++){min=MAX;for(j=2;j<=n;j++)if(que[j]==0&&min>lea[j]){min=lea[j];k=j;}que[k]=1;sum+=min;for(j=1;j<=n;j++)if(que[j]==0&&len[k][j]<lea[j])lea[j]=len[k][j];}return sum;}int main(){int i,j;int x,y;int k;int m;while(cin>>n!=0&&n){for(i=1;i<=n;i++)que[i]=0;for(i=1;i<=n;i++)for(j=1;j<=n;j++)len[i][j]=MAX;for(i=1;i<=n;i++){for(j=1;j<=n;j++){cin>>m;if(m<len[i][j])len[i][j]=len[j][i]=m;;}}cin>>m;for(i=1;i<=m;i++){cin>>x>>y;len[x][y]=len[y][x]=0;}k=Prim();cout<<k<<endl;}return 0;}
- HDU 1102 Constructing Roads
- HDU 1102 Constructing Roads
- Hdu-1102 Constructing Roads
- Hdu-1102 Constructing Roads
- hdu 1102 Constructing Roads
- HDU 1102 Constructing Roads
- hdu 1102 Constructing Roads
- hd 1102 Constructing Roads
- hdu 1102 Constructing Roads
- HDU 1102 Constructing Roads
- 1102 Constructing Roads
- HDU 1102 Constructing Roads
- HDU 1102 Constructing Roads
- hdu 1102 Constructing Roads
- Hdu 1102 - Constructing Roads
- hdu 1102 Constructing Roads
- HDU 1102 Constructing Roads
- HDU 1102 Constructing Roads
- linux设置文件权限(find+chmod)
- Struts2与DWR无法在项目中共存的解决方案
- 游戏开发新手入门之调色板和像素
- python 中lambda
- unix环境高级编程编译方法 -apue最简单编译方法(第二版)
- 1102 Constructing Roads
- 仿path首页滑动效果
- WinDev与它的中文编程语言
- boost::function用法详解
- SOA与Web Service的关系
- Z-STACK之OSAL_Nv非易失性存储解读上
- 大整数基本除法(整除)
- Repeater分页
- Linux WiFi: Deauthenticated Reason Codes