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