比赛 |
10101115 |
评测结果 |
AEWWEEEEEE |
题目名称 |
最小密度路径 |
最终得分 |
10 |
用户昵称 |
wo shi 刘畅 |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2010-11-15 09:14:50 |
显示代码纯文本
var
n,m,x,l,j,y,i,q:longint;
a,g:array[0..50,0..50]of longint;
f:Array[0..50,0..50]of boolean;
min:real;
procedure go(k,p,m:longint);
var
i:longint;
begin
if k=y then
begin
if p/m<min then min:=p/m;
exit;
end;
for i:=1 to a[k,0] do go(a[k,i],p+g[k,a[k,i]],m+1);
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,g[x,y]);
inc(a[x,0]);
a[x,a[x,0]]:=y;
f[x,y]:=true;
end;
for l:=1 to n do
for i:=1 to n do
for j:=1 to n do
if (f[i,l])and(f[l,j]) then
f[i,j]:=true;
readln(q);
for i:=1 to q do
begin
readln(x,y);
min:=maxlongint;
if not f[x,y] then writeln('OMG!')
else begin
go(x,0,0);
writeln(min:0:3);
end;
end;
close(input);
close(output);
end.