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 INF 999999 #define N 105 int road[N][N]; int s[N],city[N]; int main() { int n,i,j,m,temp,total,rec,min,s1,e1; scanf("%d",&n); memset(road,INF,sizeof(road)); for(i=1;i<=n;i++) { getchar(); for(j=1;j<=n;j++) scanf("%d",&road[i][j]); } memset(s,0,sizeof(s)); total=0; s[1]=1; scanf("%d",&m); for(i=1;i<=m;i++) { scanf("%d %d",&s1,&e1); road[s1][e1]=0; road[e1][s1]=0; } for(i=1;i<=n;i++) city[i]=road[1][i]; for(i=1;i<n;i++) { min=INF; rec=-1; for(j=1;j<=n;j++) if(!s[j]&&city[j]<min) { min=city[j]; rec=j; } s[rec]=1; total+=min; for(j=1;j<=n;j++) if(road[rec][j]<city[j]&&!s[j]) city[j]=road[rec][j]; } printf("%d\n",total); return 1; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator