2013
12-04

# 还是畅通工程

3
1 2 1
1 3 2
2 3 4
4
1 2 1
1 3 4
1 4 1
2 3 3
2 4 2
3 4 5
0

3
5

HintHint
Huge input, scanf is recommended.

/************************************************************************/
/*
hdu  还是畅通工程
最小生成树
题目大意：求连通这些村庄最少的建设公路长度
解题思路：最小生成树，所有的这些村子放在一个图中，找出一个最小生成树
*/
/************************************************************************/

#include <stdio.h>
#include <string.h>
#include <algorithm>

const int N = 101;
int map[N][N];
int mark[N];
int i,j,n;

int prim()
{
int sum = 0;
int min,t = n,k;
while(--t)
{
min = 100000;
for (i = 2; i <= n; i++)
{
if(mark[i] != 1 && min > map[1][i])
{
min = map[1][i];
k = i;
}
}
sum += min;
mark[k] = 1;
for (i = 2; i <= n; i++)
{
if(mark[i] != 1 && map[k][i] < map[1][i])
map[1][i] = map[k][i];
}
}
return sum;
}

int main()
{
int x,y,len,num;
while(scanf("%d",&n) && n != 0)
{
num = n*(n-1)/2;
memset(map,0,sizeof(map));
for (i = 1; i <= num; i++)
{
scanf("%d%d%d",&x,&y,&len);
map[x][y] = map[y][x] = len;
}
memset(mark,0,sizeof(mark));
printf("%d\n",prim());
}
return 0;
}

1. 叨，你就知足吧，你们大BOSS怕你天天坐着长出的啤酒肚，愈发嫁不掉了，才给你们安排团建的，要保持一颗感恩的心，感谢有你……就这么愉快的感恩吧，不用谢我

2. Good task for the group. Hold it up for every yeara??s winner. This is a excellent oppotunity for a lot more enhancement. Indeed, obtaining far better and much better is constantly the crucial. Just like my pal suggests on the truth about ab muscles, he just keeps obtaining much better.

3. 算法是程序的灵魂，算法分简单和复杂，如果不搞大数据类，程序员了解一下简单点的算法也是可以的，但是会算法的一定要会编程才行，程序员不一定要会算法，利于自己项目需要的可以简单了解。