| 比赛 | 
    10101115 | 
    评测结果 | 
    WEWWEEEWWE | 
    | 题目名称 | 
    最小密度路径 | 
    最终得分 | 
    0 | 
    | 用户昵称 | 
    苏轼 | 
    运行时间 | 
    0.000 s  | 
    | 代码语言 | 
    Pascal | 
    内存使用 | 
    0.00 MiB  | 
    | 提交时间 | 
    2010-11-15 10:59:46 | 
显示代码纯文本
program path(input,output);
type
  re=record
    l,en:integer;
  end;
var
  a,b,w,q,i,n,m:integer;
  tu:array[1..50,0..50]of re;
  dist:array[1..50,1..50]of real;
procedure ask(const wh,count,sum:integer);
  var
    i:integer;
  begin
    if wh<>b then
      for i:=1 to tu[wh,0].l do
        ask(tu[wh,i].en,count+1,sum+tu[wh,i].l)
    else
      if sum/count<dist[a,b] then
        dist[a,b]:=sum/count;
  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(a,b,w);
    inc(tu[a,0].l);
    tu[a,tu[a,0].l].en:=b;
    tu[a,tu[a,0].l].l:=w;
  end;
  readln(q);
  for i:=1 to q do
  begin
    readln(a,b);
    if dist[a,b]=0.0 then
    begin
      dist[a,b]:=9E9;
      ask(a,0,0);
    end;
    writeln(dist[a,b]:0:3);
  end;
  close(input);
  close(output);
end.