| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
代码!#include <stdio.h>
#include <string.h>
#define N 100+10
#define INF 9999999
int road[N][N];
int city[N];
int s[N];
int main()
{
int i,j,n,rec,max,sum;
while(scanf("%d",&n)!=EOF)
{
for(i=1;i<=n;i++)
{
getchar();
for(j=1;j<=n;j++)
scanf("%d",&road[i][j]);
}
memset(s,0,sizeof(s));
for(i=1;i<=n;i++)
city[i]=road[1][i];
s[1]=1;
sum=0;
for(i=1;i<n;i++)
{
max=INF;
for(j=1;j<=n;j++)
if(!s[j]&&city[j]<max)
{
max=city[j];
rec=j;
}
s[rec]=1;
sum+=city[rec];
for(j=1;j<=n;j++)
if(!s[j]&&road[rec][j]<city[j])
city[j]=road[rec][j];
}
printf("%d\n",sum);
}
return 1;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator