| 比赛 | 20091019练习题 | 评测结果 | WWAWAAAAAA | 
    | 题目名称 | 奶牛跨栏 | 最终得分 | 70 | 
    | 用户昵称 | kaaala | 运行时间 | 0.401 s | 
    | 代码语言 | Pascal | 内存使用 | 0.51 MiB | 
    | 提交时间 | 2009-10-19 20:09:48 | 
显示代码纯文本
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]=0 then 
	  writeln('-1') 
	else 
	  writeln(map[a,b]);
  end;
  close(input);
  close(output);
end.