标签:eof mit poj 1125 style join tor man limits ack
1 #include <iostream> 2 #include <cstdio> 3 #include <cmath> 4 #include <cstring> 5 #include <algorithm> 6 #include <queue> 7 #include <stack> 8 #include <vector> 9 #include <iomanip> 10 #include <climits> 11 using namespace std; 12 int n,map[200][200]; 13 int main(int argc, char *argv[]) 14 { 15 while(scanf("%d",&n)!=EOF) 16 { 17 if(n==0) 18 break; 19 for(int i=0;i<=n;i++) 20 { 21 for(int j=0;j<=n;j++) 22 { 23 if(i==j) 24 map[i][j]=0; 25 else 26 map[i][j]=1e9; 27 } 28 } 29 for(int i=1;i<=n;i++) 30 { 31 int m; 32 scanf("%d",&m); 33 for(int j=1;j<=m;j++) 34 { 35 int x,y; 36 scanf("%d%d",&x,&y); 37 if(map[i][x]>y) 38 map[i][x]=y; 39 } 40 } 41 for(int k=1;k<=n;k++) 42 for(int i=1;i<=n;i++) 43 for(int j=1;j<=n;j++) 44 if(map[i][j]>map[i][k]+map[k][j]) 45 map[i][j]=map[i][k]+map[k][j]; 46 int sum=1e9,k=-1; 47 for(int i=1;i<=n;i++) 48 { 49 int sum1=0;int flag=0; 50 for(int j=1;j<=n;j++) 51 { 52 if(i!=j) 53 sum1=max(sum1,map[i][j]); 54 } 55 if(sum1<sum) 56 { 57 sum=sum1; 58 k=i; 59 } 60 } 61 if(sum==1e9) 62 printf("disjoint\n"); 63 else 64 printf("%d %d\n",k,sum); 65 } 66 return 0; 67 }
标签:eof mit poj 1125 style join tor man limits ack
原文地址:https://www.cnblogs.com/huluxin/p/9784829.html