标签:style blog http color os java io for ar
1 3 0 990 692 990 0 179 692 179 0
692
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib> 10 #include <string> 11 #include <set> 12 #include <stack> 13 #define LL long long 14 #define pii pair<int,int> 15 #define INF 0x3f3f3f3f 16 using namespace std; 17 const int maxn = 510; 18 struct arc { 19 int to,w; 20 arc(int x = 0,int y = 0):to(x),w(y) {} 21 }; 22 vector<arc>g[maxn]; 23 int n,d[maxn]; 24 bool done[maxn]; 25 priority_queue< pii,vector< pii >,greater< pii > >q; 26 int prim() { 27 while(!q.empty()) q.pop(); 28 d[1] = 0; 29 q.push(make_pair(d[1],1)); 30 int ans = 0; 31 while(!q.empty()){ 32 int u = q.top().second; 33 int w = q.top().first; 34 q.pop(); 35 if(done[u]) continue; 36 done[u] = true; 37 ans = max(w,ans); 38 for(int i = 0; i < g[u].size(); i++){ 39 if(d[g[u][i].to] > g[u][i].w){ 40 d[g[u][i].to] = g[u][i].w; 41 q.push(make_pair(d[g[u][i].to],g[u][i].to)); 42 } 43 } 44 } 45 return ans; 46 } 47 int main() { 48 int t,i,j,w; 49 scanf("%d",&t); 50 while(t--) { 51 scanf("%d",&n); 52 for(i = 0; i <= n; i++) { 53 g[i].clear(); 54 d[i] = INF; 55 done[i] = false; 56 } 57 for(i = 1; i <= n; i++) { 58 for(j = 1; j <= n; j++) { 59 scanf("%d",&w); 60 if(i != j) g[i].push_back(arc(j,w)); 61 } 62 } 63 printf("%d\n",prim()); 64 } 65 return 0; 66 }
标签:style blog http color os java io for ar
原文地址:http://www.cnblogs.com/crackpotisback/p/3940844.html