比赛 |
10101115 |
评测结果 |
WWWWWWTTTT |
题目名称 |
最小密度路径 |
最终得分 |
0 |
用户昵称 |
Achilles |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2010-11-15 09:18:50 |
显示代码纯文本
program path;
var
n,m,q,i,j,k,l1,l2,a,b,c:longint;
t:double;
tab:array[1..50,1..50]of longint;
hx:array[1..50,1..50]of boolean;
ans:array[1..50,1..50,1..1000]of longint;
begin
assign(input,'path.in');
assign(output,'path.out');
reset(input);
rewrite(output);
readln(n,m);
fillchar(tab,sizeof(tab),0);
fillchar(ans,sizeof(ans),0);
fillchar(hx,sizeof(hx),false);
for i:=1 to m do
begin
readln(a,b,c);
tab[a,b]:=c;
hx[a,b]:=true;
ans[a,b,1]:=c;
end;
for k:=1 to n do
for i:=1 to n do
for j:=1 to n do
if (hx[i,k])and(hx[k,j]) then begin
hx[i,j]:=true;
for l1:=1 to m do
for l2:=1 to m-l1 do
if (ans[i,k,l1]<>0)and(ans[k,j,l2]<>0) then begin
if ans[i,j,l1+l2]=0 then begin
ans[i,j,l1+l2]:=ans[i,k,l1]+ans[k,j,l2];
end
else
if ans[i,k,l1]+ans[k,j,l2]<ans[i,j,l1+l2] then
ans[i,j,l1+l2]:=ans[i,k,l1]+ans[k,j,l2];
end;
end;
readln(q);
for i:=1 to q do
begin
readln(a,b);
t:=1.7e308;
for j:=1 to m do
if ans[a,b,j]<>0 then
if ans[a,b,j]/j<t then t:=ans[a,b,j]/j;
writeln(t:0:3);
end;
close(input);
close(output);
end.