| 比赛 | 
    10101115 | 
    评测结果 | 
    AEWWEEEEEE | 
    | 题目名称 | 
    最小密度路径 | 
    最终得分 | 
    10 | 
    | 用户昵称 | 
    donny | 
    运行时间 | 
    0.000 s  | 
    | 代码语言 | 
    Pascal | 
    内存使用 | 
    0.00 MiB  | 
    | 提交时间 | 
    2010-11-15 10:54:08 | 
显示代码纯文本
program path;
var
  n,m,i,j,k,l:longint;
  a:array[1..50,1..50]of longint;
  f:array[1..50,1..50]of double;
procedure search(const x,y,z:longint);
var
  o:longint;
begin
  if z<>0 then
    if (y/z<f[i,x])or(f[i,x]=0) then
      f[i,x]:=y/z;
  for o:=1 to n do
    if a[x,o]<>9999999 then
      search(o,y+a[x,o],z+1);
end;
begin
  assign(input,'path.in');
  reset(input);
  assign(output,'path.out');
  rewrite(output);
  readln(n,m);
  for i:=1 to n do
    for j:=1 to n do
      a[i,j]:=9999999;
  for i:=1 to m do
  begin
    read(j,k);
    readln(a[j,k]);
  end;
  for i:=1 to n do
    for j:=1 to n do
      f[i,j]:=0;
  for i:=1 to n do
    search(i,0,0);
  readln(m);
  for i:=1 to m do
  begin
    readln(j,k);
    if j=k then writeln('0.000')
    else
    if f[j,k]=0 then writeln('OMG!')
    else
    writeln(f[j,k]:0:3);
  end;
  close(input);
  close(output);
end.