记录编号 13990 评测结果 AAAAAAAAAA
题目名称 [USACO Nov07] 奶牛跨栏 最终得分 100
用户昵称 Gravatarkaaala 是否通过 通过
代码语言 Pascal 运行时间 1.175 s
提交时间 2009-10-21 19:52:30 内存使用 0.46 MiB
显示代码纯文本
program ex(input,output);
var
  k,n,m,t:longint;
  a,b:longint;
  i,j:longint;
  map:array[1..300,1..300]of longint;
function min(a,b:longint):longint;
begin
  if a<b then 
	min:=a 
  else 
	min:=b;
end;
function max(a,b:longint):longint;
begin
  if a>b then 
	max:=a 
  else 
	max:=b;
end;
begin
  assign(input,'hurdles.in');
  assign(output,'hurdles.out');
  reset(input);
  rewrite(output);
  read(n,m,t);
  for i:=1 to n do
    for j:=1 to n do
      map[i,j]:=maxlongint;
  for i:=1 to m do
    read(a,b,map[a,b]);
  for k:=1 to n do
    for i:=1 to n do
      for j:=1 to n do
        map[i,j]:=min(map[i,j],max(map[i,k],map[k,j]));
  for i:=1 to t do begin
    read(a,b);
    if map[a,b]=maxlongint then 
	  writeln('-1') 
	else 
	  writeln(map[a,b]);
  end;
  close(input);
  close(output);
end.