procedure2012
It's not worth it to know you're not worth it!

[题目来源]:Southern African 2001

[关键字]:图论

[题目大意]:股票经纪人要在一群人中散布一个传言,传言只能在认识的人中传递,题目将给出人与人的关系(是否认识),以及传言在某两个认识的人中传递所需的时间,要求程序给出以哪个人为起点,可以在好事最短的情况下,让所有人收到消息。

//====================================================================================================

[分析]:先用foyd求出多源最短路,然后枚举每一个作为起点并判断此时所需的最短时间,最后取出最优值。注意如果有一个点到其他点的最小值的最大值(所用最短时间)是maxlongint,则说明此图不连通输出无解。

[代码]:

View Code
 1 {
2 PROB:POJ1125
3 DATE:2011\10\15
4 }
5 program Project1;
6 const
7 INF = 1684300900;
8 var
9 n: longint;
10 map: array[0..200,0..200] of longint;
11
12 procedure init;
13 var
14 i, j, t, x, d: longint;
15 begin
16 readln(n);
17 if n = 0 then halt;
18 fillchar(map,sizeof(map),100);
19 for i := 1 to n do
20 begin
21 read(t);
22 for j := 1 to t do
23 begin
24 read(x,d);
25 map[i,x] := d;
26 end;
27 end;
28 end;
29
30 procedure floyd;
31 var
32 k, i, j, max, ans, p: longint;
33 f: boolean;
34 begin
35 for k := 1 to n do
36 for i := 1 to n do
37 for j := 1 to n do
38 if (i <> j) and (map[i,k] <> INF) and (map[k,j] <> INF) then
39 if map[i,j] > map[i,k]+map[k,j] then map[i,j] := map[i,k]+map[k,j];
40 ans := maxlongint;
41 for i := 1 to n do
42 begin
43 max := 0;
44 for j := 1 to n do
45 if (max < map[i,j]) and (i <> j) then max := map[i,j];
46 if max < ans then
47 begin
48 ans := max;
49 p := i;
50 end;
51 end;
52 if ans = INF then writeln('disjoint') else writeln(p,'',ans);
53 end;
54
55 begin
56 while 1 = 1 do
57 begin
58 init;
59 floyd;
60 end;
61 end.



posted on 2011-11-02 10:22  procedure2012  阅读(314)  评论(0编辑  收藏  举报