POJ
来源:互联网 发布:淘宝瑕疵磨损化妆品 编辑:程序博客网 时间:2024/06/07 01:53
只想静静的水题。prim
#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 200+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) { if (n == 0)break; sum = 0; mem(cost, INF); for (int i = 1; i < n; i++){ char s; int t; cin >> s >> t; while (t--){ char str; int cos; cin >> str >> cos; cost[i][str - 'A' + 1] = cost[str - 'A' + 1][i] = cos; } cost[i][i] = 0; } prim(); }}
阅读全文
0 0
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- 和为S的连续正数序列
- P3759道路升级
- 初学freertos第一课
- Android TextView设置值时,使一个字符串有不同颜色(多种颜色)
- python: 将列表中的字符串 连接成一个 长路径
- POJ
- 微信分享
- Ubuntu亮度调整
- 编程,从来都不晚:来自日本的82岁APP开发者
- 工作转正申请书范文一
- 基于Docker的MongoDB实现授权访问
- vs编译时出现大量IP_MULTICAST_IF,IP_MULTICAST_TTL macro redefinition的问题
- 栈帧的开辟与回退
- windows平台Mosquitto使用