标签:
Time Limit: 1000MS | Memory Limit: 65536KB | 64bit IO Format: %lld & %llu |
Description
Input
Output
Sample Input
1
3
0 990 692
990 0 179
692 179 0
Sample Output
692
Hint
Source
1 /*by SilverN*/ 2 #include<algorithm> 3 #include<iostream> 4 #include<cstring> 5 #include<cstdio> 6 #include<cmath> 7 using namespace std; 8 const int mxn=510; 9 int n,m; 10 int mp[mxn][mxn]; 11 int dis[mxn]; 12 bool vis[mxn]; 13 int ans=0; 14 int main(){ 15 int i,j; 16 int T; 17 scanf("%d",&T); 18 while(T--){ 19 scanf("%d",&n); 20 ans=0; 21 memset(mp,0x2f,sizeof mp); 22 memset(dis,0x2f,sizeof dis); 23 memset(vis,0,sizeof vis); 24 int u,v,d; 25 for(i=1;i<=n;i++) 26 for(j=1;j<=n;j++){ 27 scanf("%d",&m); 28 mp[i][j]=m; 29 if(!m)mp[i][j]=1e6; 30 } 31 dis[1]=0; 32 int pos,mini; 33 while(1){ 34 pos=0;mini=0x2f2f2f2f; 35 for(i=1;i<=n;i++){ 36 if(!vis[i] && dis[i]<mini){ 37 mini=dis[i]; 38 pos=i; 39 } 40 } 41 if(pos==0)break; 42 ans=max(ans,dis[pos]);dis[pos]=0;vis[pos]=1; 43 for(i=1;i<=n;i++){ 44 dis[i]=min(dis[i],mp[pos][i]); 45 } 46 } 47 printf("%d\n",ans); 48 } 49 return 0; 50 }
标签:
原文地址:http://www.cnblogs.com/SilverNebula/p/5891061.html