pku1125 Stockbroker Grapevine

求一个图中到其他点的最短路的最大值最小的点和这个值。

floyd一遍完事

View Code
 1 program pku1125(input,output);
 2 var
 3     f:array[0..300,0..300] of longint;
 4     n:longint;
 5 procedure init;
 6 var
 7     i,j,s,x,y:longint;
 8 begin
 9     fillchar(f,sizeof(f),30);
10     for i:=1 to n do
11     begin
12         read(s);
13         for j:=1 to s do
14         begin
15             read(x,y);
16             f[i,x]:=y;
17         end;
18         readln;
19     end;
20     for i:=1 to n do
21         f[i,i]:=0;
22 end;{ init }
23 procedure main;
24 var
25     i,j,k:longint;
26     answer,max,people:longint;
27 begin
28     for k:=1 to n do
29         for i:=1 to n do
30             for j:=1 to n do
31                 if f[i,k]+f[k,j]<f[i,j] then
32                     f[i,j]:=f[i,k]+f[k,j];
33     answer:=19950714;
34     for i:=1 to n do
35     begin
36         max:=0;
37         for j:=1 to n do
38             if (i<>j)and(f[i,j]>max) then
39                 max:=f[i,j];
40         if max<answer then
41         begin
42             answer:=max;
43             people:=i;
44         end;
45     end;
46     writeln(people,' ',answer);
47 end;{ main }
48 begin
49     readln(n);
50     while n<>0 do
51     begin
52         init;
53         main;
54         readln(n);
55     end;
56 end.
posted @ 2012-04-19 15:30  Codinginging  阅读(164)  评论(0编辑  收藏  举报