POJ 2377
来源:互联网 发布:ambari web 源码编译 编辑:程序博客网 时间:2024/06/15 20:53
#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#include<algorithm>using namespace std;#define N 1010#define Max 0x3f3f3f3fint maps[N][N], v[N], dis[N];int n, m;void prim(){ int i,j,ans=0;memset(v,0,sizeof(v));v[1]=1;for(i=1;i<n;i++){int Min=-1;int k=-1;for(j=1;j<=n;j++){if(!v[j] && maps[1][j]>Min){k=j;Min=maps[1][j];}}if(k==-1)break;ans+=maps[1][k];v[k]=1;for(j=1;j<=n;j++){if(!v[j]&&maps[1][j]<maps[k][j])maps[1][j]=maps[k][j];}}if(i<n)printf("-1\n");elseprintf("%d\n",ans);}int main(){ int i, a, b, c; while(scanf("%d%d",&n,&m)!=EOF) { memset(maps, -1, sizeof(maps)); for(i=0;i<m;i++) { scanf("%d %d %d",&a,&b,&c); if(c>maps[a][b]) maps[a][b]=maps[b][a]=c; } prim(); } return 0;}
0 0
- poj-2377
- poj 2377
- POJ 2377
- POJ 2377
- poj 2377
- POJ 2377
- poj 2377 Bad Cowtractors
- poj 2377 Bad Cowtractors
- poj 2377 Bad Cowtractors
- POJ 2377 Bad Cowtractors
- POJ 2377 Bad Cowtractors
- POJ-2377-Bad Cowtractors
- POJ 2377 Bad Cowtractors
- poj 2377 Bad Cowtractors
- POJ 2377 Bad Cowtractors
- POJ 2377 Bad Cowtractors
- Bad Cowtractors.(POJ-2377)
- poj 2377 Bad Cowtractors
- [Python]网络爬虫(二):利用urllib2通过指定的URL抓取网页内容
- composer的安装与使用
- Java 8: Streams API
- Aizu 0189
- Educational Codeforces Round 15(简单题)
- POJ 2377
- 16-07-31 Cannot refer to the non-final local variable homePageInfo defined in an enclosing scope
- 学习写makefile
- 程序员喜欢的9款最佳的Linux文件比较工具
- NOJ 1031 建筑群最长坡值 简单dp
- POJ 1151
- Struts2中的constant配置详解
- HDU 5776 sum
- Java 设计模式之原型模式的详解(创建模式)