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 |
第一次做图…一次AC…上代码…未优化,勿喷~~错误之处还望指出,谢谢~~#include<iostream> using namespace std; int a[100][100]; int t[100]; int main() { memset(t,0,sizeof(t)); int n; cin>>n; for(int i=0;i<n;i++) for(int j=0;j<n;j++)cin>>a[i][j]; int m; cin>>m; int x,y; int sum=0; for(int i=0;i<m;i++){cin>>x>>y;a[x-1][y-1]=0;a[y-1][x-1]=0;} t[0]=1; for(int i=2;i<=n;i++) { int min=1001; for(int j=0;j<n;j++) if(t[j]) { for(int k=1;k<n;k++)if(t[k]==0) { if(a[j][k]<min){min=a[j][k];x=j;y=k;} } } t[y]=1; sum+=min; } cout<<sum<<endl; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator