比赛 10101115 评测结果 WWWWWWWTEE
题目名称 最小密度路径 最终得分 0
用户昵称 itachi 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-15 11:23:17
显示代码纯文本
program t4(input,output);
var
data:array[1..50,1..50]of longint;
d:array[1..50,0..50]of integer;
fa:array[1..50]of longint;
dis:array[1..50] of real;
map:Array[1..50] of boolean;
s,t,n,m,i,j,x,y,q:longint;temp:real;

procedure main;
 var
 i,j,head,tail,k,t:longint;
  qu:array[1..100000] of integer;

 begin
   head:=1;tail:=1;
   qu[1]:=s;
   dis[s]:=0;
   repeat
    t:=qu[head];
    inc(head);
     for i:= 1 to d[t,0] do
      begin
       if fa[d[t,i]]<>0 then
        if (dis[d[t,i]]/ fa[d[t,i]]) > ( (dis[t]+data[t,d[t,i]]) /(fa[d[t,i]]+1)) then
                         begin
                          dis[d[t,i]]:= dis[t]+data[t,d[t,i]];
                          inc(fa[d[t,i]]);
                          if map[d[t,i]]   then
                            begin

                            map[d[t,i]]:=false;
                            inc(tail);
                            qu[tail]:=d[t,i];
                            end;
                          end;
       if fa [d[t,i]]=0 then
         begin
         if  dis[d[t,i]]> dis[t]+data[t,d[t,i]]
            then
            begin
              dis[d[t,i]]:= dis[t]+data[t,d[t,i]];
               inc(fa[d[t,i]]);
                 if map[d[t,i]]   then
                            begin

                            map[d[t,i]]:=false;
                            inc(tail);
                            qu[tail]:=d[t,i];
                            end;
            end;
         end;
     end;

   until head>tail;
 end;
begin
assign(input,'path.in');
reset(input);
assign(output,'path.out');
rewrite(output);
readln(n,m);
fillchar(d,sizeof(d),0);
for i:= 1 to n do

 for j:= 1 to m do
 data[i,j]:=maxint+1;

 for i:= 1 to m do
  begin
  read(x,y);
  readln(data[x,y]);
  inc(d[x,0]);
  d[x,d[x,0]]:=y;
  end;
  readln(q);
  for i:= 1 to q do
  begin
  readln(s,t);
  for j:= 1 to n do
  fa[j]:=0;
  for j:= 1 to n do
  dis[j]:=maxint+1;
  fillchar(map,sizeof(map),true);
   if s=t then writeln('0.000') else
   begin
   main;
      if dis[t]>maxint then writeln('OMG!')
      else
      begin
      temp:=(dis[t]) / (fa[t]);
     writeln(temp:0:3);
     end;
   end;
  end;
 close(input) ;
 close(output);
end.