标签:gif another wan display color ide += fun 技术分享
;i++) ans[0]+=ans[i];
printf("%d\n",ans[0]);
}
return 0;
}
Agri-Net
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 62406 | Accepted: 25818 |
Description
Input
Output
Sample Input
4 0 4 9 21 4 0 8 17 9 8 0 16 21 17 16 0
Sample Output
28
Source
#include<iostream> #include<cmath> #include<cstring> #include<cstdio> #include<cstdlib> #include<algorithm> #define inf 1<<29 using namespace std; int n,s,p,x[510],y[510]; int dis[510][510],ans[510]={0}; void prim() { bool hh[510]; int v; for(int i=1;i<=p;i++) { ans[i]=dis[1][i]; hh[i]=0; } for(int i=1;i<=p;i++) { int mi=inf; for(int j=1;j<=p;j++) { if(ans[j]<mi&&!hh[j]) {mi=ans[j];v=j;} } hh[v]=1; for(int j=1;j<=p;j++) { if(!hh[j]&&dis[v][j]<ans[j]) ans[j]=dis[v][j]; } } } int main() { while(~scanf("%d",&p)) { for(int i=1;i<=p;i++) { for(int j=1;j<=p;j++) { scanf("%d",&dis[i][j]); } } prim(); ans[0]=0; for(int i=1;i<=p;i++) ans[0]+=ans[i]; printf("%d\n",ans[0]); } return 0; }
标签:gif another wan display color ide += fun 技术分享
原文地址:http://www.cnblogs.com/SX0427/p/7811153.html