Very naked 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;
}
POJ 1125 stockbroker Grapevine "Floyd"