POJ 1125
#include<iostream> #include<stdio.h> #define MAXN 102 #define inf 100000000 using namespace std; int _m[MAXN][MAXN]; int min1[MAXN][MAXN]; int pre1[MAXN][MAXN]; typedef int elem_t; void floyd_warshall(int n,elem_t mat[][MAXN],elem_t min[][MAXN],int pre[][MAXN]); int main() { //freopen("acm.acm","r",stdin); int num; int i; int j; int k; int n; int bod; int time; int max; int min; while(cin>>num) { if(num == 0) break; for(i = 0; i < num; ++ i) for(j = 0; j < num; ++ j) { _m[i][j] = inf; if(i == j) _m[i][j] = 0; } for(i = 0; i < num; ++ i) { cin>>k; for(j = 0; j < k; ++ j) { cin>>n>>time; _m[i][n-1] = time; } } floyd_warshall(num,_m,min1,pre1); min = inf; for(i = 0; i < num; ++ i) { max = 0; for(j = 0; j < num; ++j) { if(min1[i][j] > max) { max = min1[i][j]; } } if(max < min) { min = max; bod = i + 1; } } cout<<bod <<" "<<min<<endl; } } void floyd_warshall(int n,elem_t mat[][MAXN],elem_t min[][MAXN],int pre[][MAXN]){ int i,j,k; for (i=0;i<n;i++) for (j=0;j<n;j++) min[i][j]=mat[i][j],pre[i][j]=(i==j)?-1:i; for (k=0;k<n;k++) for (i=0;i<n;i++) for (j=0;j<n;j++) if (min[i][k]+min[k][j]<min[i][j]) min[i][j]=min[i][k]+min[k][j],pre[i][j]=pre[k][j]; }
关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。
技术网站地址: vmfor.com