题解:啦啦啦啦,萌萌哒Floyd算法——唯一的不同就是每次将 if (a[i,k]+a[k,j])<a[i,j] then a[i,j]:=a[i,k]+a[k,j] 改成 a[i,j]:=min(a[i,j],max(a[i,k],a[k,j])) 即可,即变成了一个最瘦路径问题,然后没然后了。。。(能把O(N^3)的Floyd在N<=300时硬生生的卡到1996ms我也是醉了)
1 var
2 i,j,k,l,m,n,t:longint;
3 a:array[0..500,0..500] of int64;
4 function min(x,y:int64):int64;
5 begin
6 if x<y then min:=x else min:=y;
7 end;
8 function max(x,y:int64):int64;
9 begin
10 if x>y then max:=x else max:=y;
11 end;
12 begin
13 fillchar(a,sizeof(a),-1);
14 readln(n,m,t);
15 for i:=1 to m do
16 begin
17 readln(j,k,l);
18 if (a[j,k]=-1) or (a[j,k]>l) then a[j,k]:=l
19 end;
20 for k:=1 to n do
21 for i:=1 to n do
22 begin
23 if (a[i,k]=-1) or (i=k) then continue;
24 for j:=1 to n do
25 begin
26 if (i=j) or (k=j) or (a[k,j]=-1) then continue;
27 if a[i,j]<>-1 then
28 a[i,j]:=min(a[i,j],max(a[i,k],a[k,j]))
29 else
30 a[i,j]:=max(a[i,k],a[k,j]);
31 end;
32 end;
33 for i:=1 to t do
34 begin
35 readln(j,k);
36 writeln(a[j,k]);
37 end;
38 end.
39