题目传送门
/*
最短路:Floyd模板题
主要是两点最短的距离和起始位置
http://blog.****.net/y990041769/article/details/37955253
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
using namespace std;
const int MAXN = + ;
const int INF = 0x3f3f3f3f;
int d[MAXN][MAXN];
void Floyd_Warshall(int n)
{
for (int k=; k<=n; ++k)
{
for (int i=; i<=n; ++i)
{
for (int j=; j<=n; ++j)
{
if (d[i][j] > d[i][k] + d[k][j])
d[i][j] = d[i][k] + d[k][j];
}
}
}
}
void work(int n)
{
Floyd_Warshall (n);
int res; int ans = INF; int num;
for (int i=; i<=n; ++i)
{
res = ;
for (int j=; j<=n; ++j)
{
if (i == j) continue;
if (res < d[i][j]) res = d[i][j];
}
if (ans > res)
{
ans = res;
num = i;
}
}
printf ("%d %d\n", num, ans);
}
int main(void) //POJ 1125 Stockbroker Grapevine
{
//freopen ("E.in", "r", stdin);
int n, m;
while (~scanf ("%d", &n) && n)
{
for (int i=; i<=n; ++i)
for (int j=; j<=n; ++j) d[i][j] = INF;
for (int i=; i<=n; ++i)
{
scanf ("%d", &m);
int x, y;
for (int j=; j<=m; ++j)
{
scanf ("%d%d", &x, &y);
d[i][x] = y;
}
}
work (n);
}
return ;
}