标签:
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 23376 | Accepted: 10797 |
Description
Input
Output
Sample Input
1 3 0 990 692 990 0 179 692 179 0
Sample Output
692
Hint
Source
1 #include<iostream> 2 #include<queue> 3 #include<cstdio> 4 #include<cstring> 5 #include<cmath> 6 #include<algorithm> 7 using namespace std; 8 #define size 500 9 #define inf 999999999 10 int m[size+5][size+5]; 11 int lowcost[size+5]; 12 /*struct cmp{ 13 operator bool(int a,int b){ 14 return lowcost[a]> lowcost[b]; 15 } 16 }; */ 17 void prime(int n){ 18 int i=0,j; 19 int k=0; 20 //priority_queue<int, vector<int>,cmp> q; 21 lowcost[0]=0; 22 for(i=1;i<n;i++){ 23 lowcost[i]=m[0][i]; 24 //q.push(lowcost[i]); 25 } 26 int max=0; 27 for(i=1;i<n;i++){ 28 int min=inf; 29 for(j=1;j<n;j++){ 30 if(lowcost[j]&&lowcost[j]<min){ 31 min=lowcost[j]; 32 k=j; 33 } 34 } 35 if(min>max){ 36 max=min; 37 } 38 //cout<<"i: "<<lowcost[i]<<endl; 39 for(j=1;j<n;j++){ 40 if(lowcost[j]>m[k][j]){ 41 lowcost[j]=m[k][j]; 42 } 43 } 44 lowcost[k]=0; 45 } 46 /*for(i=0;i<n;i++) 47 cout<<lowcost[i]<<endl;*/ 48 cout<<max<<endl; 49 } 50 int main(){ 51 int n; 52 scanf("%d",&n); 53 while(n--){ 54 int i,j,s; 55 scanf("%d",&s); 56 for(i=0;i<s;i++){ 57 for(j=0;j<s;j++){ 58 scanf("%d",&m[i][j]); 59 } 60 } 61 prime(s); 62 } 63 return 0; 64 }
标签:
原文地址:http://www.cnblogs.com/Deribs4/p/4288754.html