标签:des style color java os io strong for
3 1 2 1 0 1 3 2 0 2 3 4 0 3 1 2 1 0 1 3 2 0 2 3 4 1 3 1 2 1 0 1 3 2 1 2 3 4 1 0
3 1 0
#include<stdio.h> #include<string.h> #define m 100000000 int map[110][110],dis[110],s[110],ant,n,min,k; void prim() { int i,j; memset(s,0,sizeof(s)); for(i=1;i<=n;i++) { dis[i]=map[1][i]; } s[1]=1; for(i=1;i<n;i++) { min=m,k; for(j=1;j<=n;j++) { if(s[j]==0&&dis[j]<min) { min=dis[j]; k=j; } } s[k]=1; ant+=min; for(j=1;j<=n;j++) { if(s[j]==0&&dis[j]>map[k][j]) { dis[j]=map[k][j]; } } } } int main() { int i,j,a,b,c,d; while(scanf("%d",&n)==1&&n) { memset(map,0,sizeof(map)); for(i=1;i<=n*(n-1)/2;i++) { scanf("%d%d%d%d",&a,&b,&c,&d); if(d==1) map[a][b]=map[b][a]=0;//两个城镇之间已经建好了的话,之间的费用就是0了 else map[a][b]=map[b][a]=c; } ant=0; prim(); printf("%d\n",ant); } }
标签:des style color java os io strong for
原文地址:http://blog.csdn.net/hpuhjl/article/details/38517511