标签:des style blog color strong os
#include <stdio.h> #include <string.h> #define MAX_NUM 105 int map[MAX_NUM][MAX_NUM], n; int prime() { int pos, min, result = 0, visited[MAX_NUM], low[MAX_NUM]; memset(visited, 0, sizeof(visited)); visited[1] = 1; pos = 1; for(int i = 1; i <= n; i++) if(i != pos) low[i] = map[pos][i]; for(int i = 1; i < n; i++) { min = 100000000; for(int j = 1; j <= n; j++) { if(visited[j] == 0 && low[j] < min) { min = low[j]; pos = j; } } result += min; visited[pos] = 1; for(int j = 1; j <= n; j ++) { if(visited[j] == 0 && low[j] > map[pos][j]) low[j] = map[pos][j]; } } return result; } int main() { scanf("%d", &n); for(int i = 1; i <= n; i++) for(int j = 1; j <=n; j++) { scanf("%d", &map[i][j]); if(map[i][j] == 0) map[i][j] = 1000000; } printf("%d\n", prime()); return 0; }
标签:des style blog color strong os
原文地址:http://blog.csdn.net/userluoxuan/article/details/37775975