很裸的floyd
#include<cstdio>
#include<string.h>
#include<algorithm>
#define maxn 201
#define inf 100000
using namespace std;
int map[maxn][maxn],n,x,y,m;;
int main()
{
while(1)
{
scanf("%d",&n);
if(n==0)break;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
map[i][j]=inf;
for(int i=1;i<=n;i++)
{
scanf("%d",&m);
for(int j=1;j<=m;j++)
scanf("%d%d",&x,&y),map[i][x]=y;
}
for(int k=1;k<=n;k++)
for(int i=1;i<=n;i++)if(k!=i)
for(int j=1;j<=n;j++)if(j!=k&&j!=i&&map[i][k]+map[k][j]<map[i][j])
map[i][j]=map[i][k]+map[k][j];
int ans=inf,ansj=-1;
for(int i=1;i<=n;i++)
{
int tem=-1;
for(int j=1;j<=n;j++)
{
if(map[i][j]>tem&&map[i][j]!=inf)tem=map[i][j];
if(map[i][j]==inf&&i!=j){tem=-1;break;}
}
if(tem<ans&&tem!=-1)ans=tem,ansj=i;
}
if(ansj==-1)printf("disjoint\n");else
printf("%d %d\n",ansj,ans);
}
return 0;
}