比赛 10101115 评测结果 WWAAWWWWWW
题目名称 最小密度路径 最终得分 20
用户昵称 ybh 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-15 10:30:54
显示代码纯文本
{最小密度路径
 最短路径 
 Author: yangbohua
 Time: 2010-11-15 10:33}

program path;
var
  f:array[1..100,1..100,1..2] of longint;
  n,m,q,i,j,k,r1,r2,r3:longint;

begin
  assign(input,'path.in');
  reset(input);
  assign(output,'path.out');
  rewrite(output);

  readln(n,m);
  for i:=1 to m do
  begin
    readln(r1,r2,r3);
    if (f[r1,r2,1]=0) or ((f[r1,r2,1]>0) and (r3<f[r1,r2,1])) then
    begin
      f[r1,r2,1]:=r3;
      f[r1,r2,2]:=1;
    end;
  end;

  for k:=1 to n do
    for i:=1 to n do
      for j:=1 to n do
        if (f[i,k,1]>0) and (f[k,j,1]>0) then
          if (f[i,j,1]=0) or ((f[i,k,1]+f[k,j,1])/(f[i,k,2]+f[k,j,2])<f[i,j,1]/f[i,j,2]) then
          begin
            f[i,j,1]:=f[i,k,1]+f[k,j,1];
            f[i,j,2]:=f[i,k,2]+f[k,j,2];
          end;

  readln(q);
  for i:=1 to q do
  begin
    readln(r1,r2);
    if f[r1,r2,2]>0
      then writeln(f[r1,r2,1]/f[r1,r2,2]:0:3)
      else writeln('OMG!');
  end;

  close(input);
  close(output)
end.