POJ
来源:互联网 发布:tcp编程用什么语言 编辑:程序博客网 时间:2024/05/18 03:54
#include <stdio.h>#include <string.h>#include <iostream>#include<algorithm>#include <vector>#include <queue>#include <string>#include <math.h>#include <stdlib.h>using namespace std;#define INF 0x3f3f3f3f#define mem(arr,a) memset(arr,a,sizeof(arr))#define V 2000+5#define LL long long int#define E 320000#define pow(a) ((a)*(a))int n, m;int cost[V][V];int minCost[V];int vis[V];int sum;void prim(){ for (int i = 1; i <= n; i++){ minCost[i] = cost[1][i]; vis[i] = 0; } while (1){ int v = -1; for (int i = 1; i <= n; i++){ if (!vis[i] && (v == -1 || minCost[i] < minCost[v]))v = i; } if (v == -1)break; vis[v] = 1; sum += minCost[v]; for (int i = 1; i <= n; i++){ if (minCost[i]>cost[v][i])minCost[i] = cost[v][i]; } } cout << sum << endl;}int main(){ while (cin >> n) { sum = 0; for (int i = 1; i <= n; i++){ for (int j = 1; j <= n; j++){ cin >> cost[i][j]; } } prim(); }}
阅读全文
0 0
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- [DP] POJ1661
- Codeforces 846 A Curriculum Vitae(dp)
- Ubuntu下通过mentohust使用校园网
- 百度开源项目推荐
- Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use
- POJ
- mongoDB导出数据库所有集合内容到json文件
- POJ
- 将jar包安装到本地仓库
- JavaScript HTML DOM 添加和删除节点(HTML 元素)
- JS中 toString() & valueOf()
- Lucene6.5.0 下中文分词IKAnalyzer编译和使用
- windows系统部署安装vue.js的详细步骤
- 栈和队列——用栈来求解汉诺塔问题(非递归)(java实现)