最小生成树 prim----------------
/*最小生成树,用Prim算法
使用BZ数组
*/
#include<stdio.h>
#define INF 200
int g[110][110],bz[110],low[110];
int min,ans,Q,n,a,b;
void prim()
{ int i,j,k,x;
for (i=1;i<=n;i++)
{ low[i]=g[1][i]; bz[i]=0; }
ans=0; bz[1]=1;
for (i=1;i<n;i++)
{ printf("low[]\n");
for (x=1;x<=n;x++)
printf("%d ",low[x]); printf("\n");
printf("bz[]\n");
for (x=1;x<=n;x++)
printf("%d ",bz[x]); printf("\n");
min=INF;
for (k=1;k<=n;k++)
if ( (low[k]<min)&& ( bz[k]==0) ) { min=low[k]; j=k; }
ans+=min;
printf("min=%d ans=%d\n",min, ans);
bz[j]=1;
for (k=1;k<=n;k++)
if ( (g[j][k]<low[k])&&(bz[k]==0)) low[k]=g[j][k];
}
}
int main()
{ int i,j;
while (scanf("%d",&n)!=EOF)
{
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
scanf("%d",&g[i][j]);
prim();
printf("ans=%d\n",ans);
}
}
/*
5
200 10 200 11 200
10 200 13 18 200
200 13 200 12 15
11 18 12 200 16
200 200 15 16 200
*/