POJ 1258
来源:互联网 发布:周杰伦听妈妈的话知乎 编辑:程序博客网 时间:2024/05/21 08:56
最小生成树的水提,纪念一下我的第一到图论题
#include<stdio.h>#include<string.h>#include<algorithm>#define INF 1000000using namespace std;int judge[105];int cost[105][105];int mincost[105];int main(){ int n,ans; while(scanf("%d",&n)!=EOF){ for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ scanf("%d",&cost[i][j]); } } for(int i=1;i<=n;i++){ mincost[i]=INF; judge[i]=0; } mincost[1]=0; ans=0; while(1){ int x=-1; for(int i=1;i<=n;i++){ if(judge[i]==0&&(x==-1||mincost[i]<mincost[x])) x=i; } if(x==-1) break; judge[x]=1; ans+=mincost[x]; for(int i=1;i<=n;i++){ mincost[i]=min(mincost[i],cost[x][i]); } } printf("%d\n",ans); } return 0;}
0 0
- Poj 1258
- poj 1258
- POJ 1258
- poj 1258
- POJ 1258
- POJ 1258
- poj 1258
- poj 1258
- poj 1258
- POJ 1258
- poj 1258
- poj 1258
- poj 1258
- POJ 1258
- POJ 1258
- POJ 1258
- POJ 1258
- POJ - 1258
- 运动是IQ大厦的砖瓦
- Effective Java 第6条 消除过期的对象引用
- EL表达式
- apache安装与配置重定向
- 杭电acm之1516--String Distance and Transform Process
- POJ 1258
- Samba服务器搭建
- Linux学习笔记之——普通用户使用sudo命令
- ubuntu 安装卸载软件方法
- hdu 1242
- acm之路 之插入排序
- Subsets
- 《Mali OpenCL SDK v1.1.0》教程样例之一“Hello World”
- 今年暑假不AC-贪心算法