比赛 |
10101115 |
评测结果 |
AAAAAAAAAA |
题目名称 |
最小密度路径 |
最终得分 |
100 |
用户昵称 |
王者自由 |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2010-11-15 10:52:06 |
显示代码纯文本
program path;
const MAX=100000000;
var n,m,i,j,k,l,q,x,y:longint;
A:array[0..50,0..50]of longint;
F:array[0..50,0..50,0..50]of longint;
S:array[0..50,0..50]of extended;
begin
assign(input,'path.in'); reset(input);
assign(output,'path.out'); rewrite(output);
readln(n,m);
for i:=1 to n do
for j:=1 to n do
begin
A[i,j]:=MAX;
S[i,j]:=MAX;
for k:=1 to n do F[i,j,k]:=MAX;
end;
for i:=1 to m do
begin
readln(x,y,q);
if q<A[x,y] then A[x,y]:=q;
end;
for i:=1 to n do
for j:=1 to n do
if A[i,j]<>MAX then F[i,j,1]:=A[i,j];
for l:=2 to n do
for k:=1 to n do
for i:=1 to n do
for j:=1 to n do
if F[i,j,l]>F[i,k,l-1]+F[k,j,1]
then F[i,j,l]:=F[i,k,l-1]+F[k,j,1];
for i:=1 to n do
for j:=1 to n do
for k:=1 to n do
if (F[i,j,k]<>MAX)and(S[i,j]>F[i,j,k]/k)
then S[i,j]:=F[i,j,k]/k;
readln(q);
for i:=1 to q do
begin
readln(x,y);
if S[x,y]=MAX
then writeln('OMG!')
else writeln(S[x,y]:0:3);
end;
close(input); close(output);
end.