#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 == )
break;
for(i = ; i < num; ++ i)
for(j = ; j < num; ++ j)
{
_m[i][j] = inf;
if(i == j)
_m[i][j] = ;
} for(i = ; i < num; ++ i)
{
cin>>k;
for(j = ; j < k; ++ j)
{
cin>>n>>time;
_m[i][n-] = time;
}
}
floyd_warshall(num,_m,min1,pre1);
min = inf;
for(i = ; i < num; ++ i)
{
max = ;
for(j = ; j < num; ++j)
{
if(min1[i][j] > max)
{
max = min1[i][j];
}
}
if(max < min)
{
min = max;
bod = i + ;
}
}
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=;i<n;i++)
for (j=;j<n;j++)
min[i][j]=mat[i][j],pre[i][j]=(i==j)?-:i;
for (k=;k<n;k++)
for (i=;i<n;i++)
for (j=;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