- 最短路上的统计
- 2014-11-06 21:12:03 @
program floyd;
var f,an:array[1..100,1..100]of longint;
n,m,p,a,b,i,j,k:longint;
begin
assign(input,'in');
reset(input);
readln(n,m);
for i:=1 to n do for j:=1 to n do if i=j then f[i,j]:=0 else f[i,j]:=100000;
for i:=1 to m do begin readln(a,b);f[a,b]:=1;f[b,a]:=1;end;
for k:=1 to n do for i:=1 to n do for j:=1 to n do
begin
if (k<>i)and(i<>j)and(j<>k)and(f[i,k]+f[k,j]=f[i,j]) then inc(an[i,j],f[i,j]-1);
if f[i,k]+f[k,j]<f[i,j] then begin f[i,j]:=f[i,k]+f[k,j];an[i,j]:=f[i,j];end;
end;
readln(p);
for i:=1 to p do begin readln(a,b);writeln(an[i,j]);end;
close(input);
end.
1 条评论
-
xuxiang LV 7 @ 2014-11-06 21:14:06
思想就是 在弗洛伊德中 如果是最短的就更新an【i,j】 如果一样短就an【i,j】:=an[i,j]+f[i,j]-1 就是再加一个点
哪里错了啊啊啊!!!!
- 1