比赛 10101115 评测结果 WEWWEEEEEE
题目名称 最小密度路径 最终得分 0
用户昵称 maxiem 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-15 10:07:28
显示代码纯文本
program path;
var
  table,map:array [0..50,0..50] of longint;
  dist:array [1..50,1..50] of record
    d,w:longint;
  end;
  q:array [1..2500] of longint;
  f:array [1..50] of boolean;
  head,tail,i,j,n,m,w,x,y:longint;
procedure spfa;
var now:longint;
begin
  for i:=1 to n do begin
    for j:=1 to n do begin
	  dist[i,j].d:=maxlongint;
	  dist[i,j].w:=1;
	end;
    fillchar (f,sizeof(f),0);
    dist[i,i].d:=0;dist[i,i].w:=0;f[i]:=true;q[1]:=i;
    head:=1;tail:=1;
    while head<=tail do begin
      now:=q[head];
      for j:=1 to map[now,0] do begin
        if dist[i,map[now,j]].d/dist[i,map[now,j]].w>(dist[i,now].d+table[now,map[now,j]])/(dist[i,now].w+1) then begin
      	  dist[i,map[now,j]].d:=dist[i,now].d+table[now,map[now,j]];
		  dist[i,map[now,j]].w:=dist[i,now].w+1;
       	  if f[map[now,j]]=false then begin
            tail:=(tail+1) mod (n*n);
       	    q[tail]:=map[now,j];
	        f[map[now,j]]:=true;
	      end;
	    end;
      end;
      f[now]:=false;
      head:=(head+1) mod (n*n);
    end;
  end;
end;
begin
  assign (input,'path.in');
  reset (input);
  readln (n,m);
  for i:=1 to m do begin
    readln (x,y,w);
	table[x,y]:=w;
	inc(map[x,0]);
	map[x,map[x,0]]:=y;
  end;
  assign (output,'path.out');
  rewrite (output);
  spfa;
  readln (w);
  for i:=1 to w do begin
    readln (x,y);
    if dist[x,y].d=0 then writeln ('OMG!') else	writeln (dist[x,y].d/dist[x,y].w:0:3);
  end;
  close (input);
  close (output);
end.