记录编号 15424 评测结果 AAAAAAAAAA
题目名称 [USACO Nov07] 奶牛跨栏 最终得分 100
用户昵称 Gravatarchengyang 是否通过 通过
代码语言 Pascal 运行时间 0.743 s
提交时间 2009-11-12 21:14:12 内存使用 0.28 MiB
显示代码纯文本
program hurdles;   
var  
  map:array[0..301,0..301]of longint;   
  i,j,k,m,n,t,a,b,c:longint;   
begin  
  assign(input,'hurdles.in');   
  assign(output,'hurdles.out');   
  reset(input); rewrite(output);   
  readln(n,m,t);   
  for i:=0 to 301 do  for j:=0 to 301 do map[i,j]:=-1;   
  for i:=1 to m do begin  
    readln(a,b,c);   
    map[a,b]:=c;   
  end;   
  for k:=1 to n do  
    for i:=1 to n do  
      for j:=1 to n do  
        if (map[i,k]>0)and(map[k,j]>0) then begin  
          a:=map[i,j]; b:=map[i,k]; c:=map[k,j];   
          if c>b then b:=c;   
          if (a>b)or(a=-1)then map[i,j]:=b;   
  end;   
  for i:=1 to t do begin  
    readln(a,b);   
    writeln(map[a,b]);   
  end;   
  close(input); close(output);   
END.  
program hurdles;
var
  map:array[0..301,0..301]of longint;
  i,j,k,m,n,t,a,b,c:longint;
begin
  assign(input,'hurdles.in');
  assign(output,'hurdles.out');
  reset(input); rewrite(output);
  readln(n,m,t);
  for i:=0 to 301 do  for j:=0 to 301 do map[i,j]:=-1;
  for i:=1 to m do begin
    readln(a,b,c);
    map[a,b]:=c;
  end;
  for k:=1 to n do
    for i:=1 to n do
      for j:=1 to n do
        if (map[i,k]>0)and(map[k,j]>0) then begin
          a:=map[i,j]; b:=map[i,k]; c:=map[k,j];
          if c>b then b:=c;
          if (a>b)or(a=-1)then map[i,j]:=b;
  end;
  for i:=1 to t do begin
    readln(a,b);
    writeln(map[a,b]);
  end;
  close(input); close(output);
END.