标签:hid opera traffic class eve span any mini 最小值
Input
Output
Sample Input
1 3 0 990 692 990 0 179 692 179 0
Sample Output
692
Hint
1 #include <iostream> 2 using namespace std; 3 #include<string.h> 4 #include<set> 5 #include<stdio.h> 6 #include<math.h> 7 #include<queue> 8 #include<map> 9 #include<algorithm> 10 #include<cstdio> 11 #include<cmath> 12 #include<cstring> 13 #include <cstdio> 14 #include <cstdlib> 15 #include<cstring> 16 int n; 17 int a[510]; 18 int find (int x) 19 { 20 if(a[x]==x) 21 return x; 22 return a[x]=find(a[x]); 23 } 24 int balabalanengliang(int x,int y) 25 { 26 int x1=find(x); 27 int y1=find(y); 28 if(x1==y1) 29 return 1; 30 a[y1]=x1; 31 return 0; 32 } 33 struct lll 34 { 35 int x,y,len; 36 }s; 37 struct cmp1{ 38 bool operator ()(lll &a,lll &b){ 39 return a.len>b.len;//最小值优先 40 } 41 }; 42 priority_queue<lll,vector<lll>,cmp1>TM; 43 44 int main() 45 { 46 int t; 47 cin>>t; 48 while(t--) 49 { 50 cin>>n; 51 memset(a,0,sizeof(a)); 52 for(int i=1;i<=n;i++) 53 { 54 for(int j=1;j<=n;j++) 55 { 56 a[j]=j; 57 int t; 58 cin>>t; 59 if(i==j) 60 continue; 61 s.x=i; 62 s.y=j; 63 s.len=t; 64 TM.push(s); 65 } 66 } 67 int temp; 68 while(!TM.empty()) 69 { 70 if(balabalanengliang(TM.top().x,TM.top().y)) 71 { 72 TM.pop(); 73 continue; 74 } 75 temp=TM.top().len; 76 TM.pop(); 77 } 78 cout<<temp<<endl; 79 } 80 return 0; 81 }
标签:hid opera traffic class eve span any mini 最小值
原文地址:http://www.cnblogs.com/dulute/p/7295578.html