#include <cstdio> #include <iostream> #include <algorithm> #include <queue> #include <stack> #include <cstdlib> #include <cmath> #include <set> #include <map> #include <vector> #include <cstring> #define INF 100000000 using namespace std; int n; int a[105][105]; int ans[105]; int main(){ while(cin >> n,n){ for(int i = 1;i <= n;i++){ for(int j = 1;j <= n;j++){ a[i][j] = INF; } } int m; for(int i = 1;i <= n;i++){ scanf("%d",&m); for(int j = 1;j <= m;j++){ int x,v; scanf("%d%d",&x,&v); a[i][x] = v; } } for(int k = 1;k <= n;k++){ for(int i = 1;i <= n;i++){ for(int j = 1;j <= n;j++){ a[i][j] = min(a[i][j],a[i][k]+a[k][j]); } } } int max = INF; int maxn; for(int i = 1;i <= n;i++){ ans[i] = 0; for(int j = 1; j <= n;j++){ if(i != j && a[i][j] > ans[i]){ ans[i] = a[i][j]; } } if(ans[i] < max){ max = ans[i]; maxn = i; } } if(max >= INF){ cout << "disjoint" << endl; } else{ printf("%d %d\n",maxn,max); } } return 0; }
时间: 2024-11-05 19:41:14