水题,FLOYD0ms过掉,题目大意是说给你n个人可以联系的人和联系他们需要花费的时间,你求出把所有人都联系到的最少花费时间,显然要用floyd求出每一个人对其他人的最少花费,然后求出每一行中最大的值,在这些最大值中取一个最小的就可以了,记得处理i==j的情况,居然没能1Y,杯具。。。
#include <stdio.h>
const int size = 101;
const int eps = 1<<30-1;
int mapp[size][size];
void floyd(int n)
{
for (int i = 1; i <= n; i ++){
for (int j = 1; j <= n; j ++){
for (int k = 1; k <= n; k ++){
if (mapp[j][k] > mapp[j][i]+mapp[i][k] && j!=k){
mapp[j][k] = mapp[j][i]+mapp[i][k];
}
}
}
}
}
int main()
{
int n;
while (scanf("%d", &n) != EOF && n){
for (int i = 1; i <= n; i ++){
for (int j = 1; j <= n; j ++){
mapp[i][j] = eps;
}
mapp[i][i] = 0;
}
int IN[size]={0}, OUT[size]={0};
for (int i = 1; i <= n; i ++){
int t;
scanf("%d", &t);
while (t --){
int a, b;
scanf("%d%d", &a, &b);
if (mapp[i][a] > b)
mapp[i][a] = b;
IN[a] ++, OUT[b] ++;
}
}
bool check = false;
for (int i = 1; i <= n; i ++){
if (!IN[i] && !OUT[i]){
check = true;
}
}
if (check){
printf("disjoint\n");
continue;
}
floyd(n);
int ii , tt = eps;
for (int i = 1; i <= n; i ++){
int maxx = -1;
int checkk = false;
for (int j = 1; j <= n; j ++){
if (mapp[i][j] == eps ){checkk = true;break;}
if (maxx < mapp[i][j] && i!=j){
maxx = mapp[i][j];
}
}
if (tt > maxx && maxx != -1 && !checkk){
ii = i, tt = maxx;
}
}
printf("%d %d\n", ii, tt);
}
return 0;
}