比赛 20091019练习题 评测结果 AAAAAAAAAA
题目名称 奶牛跨栏 最终得分 100
用户昵称 bing 运行时间 0.298 s
代码语言 Pascal 内存使用 0.51 MiB
提交时间 2009-10-19 20:43:04
显示代码纯文本
program bing;
var
 f1,f2:text;
 n,m,i,j,k,x,y:integer;
 t,t1,t2:longint;
 a:array[1..300,1..300] of longint;
begin
 assign(f1,'hurdles.in');reset(F1);
 assign(f2,'hurdles.out');rewrite(f2);
 readln(f1,n,m,t);
 for i:=1 to n do
 for j:=1 to n do a[i,j]:=-1;
 for i:=1 to m do readln(f1,x,y,a[x,y]);
 for k:=1 to n do
 for i:=1 to n do
 for j:=1 to n do
  begin
   if (i<>j)and(j<>k)and(i<>k) then
   begin
   if (a[i,k]>0)and(a[k,j]>0) then
    begin
     if a[i,k]<a[k,j] then t1:=a[k,j] else t1:=a[i,k];
    end
   else
    begin
     t1:=-1;
    end;
   if (t1<>-1) then
   begin
    if a[i,j]<>-1 then begin if t1<a[i,j] then a[i,j]:=t1;end
    else a[i,j]:=t1;
   end;
   end;
  end;
 for t2:=1 to t do
 begin
  readln(f1,x,y);
  writeln(f2,a[x,y]);
 end;
 close(f1);close(F2);
end.