求一个起点 这个起点到图中所有点的最大距离最短
水题不多说
代码:
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
const int maxn = 105;
const int INF = 0x3f3f3f3f;
int Adj[maxn][maxn];
int n;
void Floyd(){
for(int k = 1;k <= n;++k){
for(int i = 1;i <= n;++i){
for(int j = 1;j <= n;++j){
Adj[i][j] = min(Adj[i][j],Adj[i][k] + Adj[k][j]);
}
}
}
}
void solve(){
int lable,ans = INF;
for(int i = 1;i <= n;++i){
int temp = 0;
for(int j = 1;j <= n;++j){
temp = max(temp,Adj[i][j]);
}
if(temp < ans){
ans = temp;
lable = i;
}
}
if(ans < INF) printf("%d %d\n",lable,ans);
else printf("disjoint\n");
}
int main(){
while( scanf("%d",&n) & n ){
memset(Adj,0x3f,sizeof(Adj));
for(int i = 1;i <= n;++i){
int k;scanf("%d",&k);
for(int j = 0;j < k;++j){
int v,w;
scanf("%d %d",&v,&w);
Adj[i][v] = w;
}
Adj[i][i] = 0;
}
Floyd();
solve();
}
return 0;
}