记录编号 15235 评测结果 AAAAAAAAAA
题目名称 [USACO Nov07] 奶牛跨栏 最终得分 100
用户昵称 Gravatarbing 是否通过 通过
代码语言 Pascal 运行时间 1.392 s
提交时间 2009-11-11 08:06:12 内存使用 0.46 MiB
显示代码纯文本
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.