I and OI
Past...

题意:对于一个点i,设f(i)=max{mindis[i,j]} (j≠i).

其中mindis是各个点对之间的最短路.求min{f(i)} (1<=i<=n).

分析:floyd求出最短路即可.

code:

var   person,time,n,i,j,k,p,min,max,mini,minperson:longint;
      map:array[0..110,0..110] of longint;
      f:boolean;



begin

      readln(n);
      while n<>0 do
      begin
            fillchar(map,sizeof(map),1);
            for i:=1 to n do
            begin
                  read(p);
                  for j:=1 to p do
                  begin
                        read(person,time);
                        map[i,person]:=time;
                  end;
                  readln;
            end;

            for k:=1 to n do
               for i:=1 to n do
                  for j:=1 to n do
                  if map[i,k]+map[k,j]<map[i,j] then
                  map[i,j]:=map[i,k]+map[k,j];



            min:=maxlongint;
            for i:=1 to n do
            begin
                  max:=-maxlongint;
                  f:=true;
                  for j:=1 to n do
                  begin
                        if i=j then continue;
                        if map[i,j]=16843009 then
                        begin f:=false; break; end;
                        if map[i,j]>max then max:=map[i,j];
                  end;

                  if f then
                    if max<min then
                    begin min:=max; minperson:=i; end;
            end;

            writeln(minperson,' ',min);
            readln(n);
      end;
end.
posted on 2011-08-10 12:54  exponent  阅读(303)  评论(0编辑  收藏  举报