道路值守
Description
有一个有
N
个点,
Data Constraint
N
<=
Solution
先用
Floyd
最短路算法求出任意两点之间的最短距离。
(下面的
FX,Y
表示
X
,
然后枚举一个点
X
,再枚举
Code(Pacal)
var
n,m,j,k,l,i,o,x,y,c,kk,ans:longint;
be,ne,bh,bq:array[0..10000000] of longint;
bz:array[0..1000] of boolean;
dd,u,p,qy:qword;
way:array[0..1000,0..5000] of qword;
dy:array[0..270000,1..2] of qword;
ok:array[0..250000] of qword;
f,bc:array[0..500,0..500] of longint;
dl,mi,sd:array[0..1000] of longint;
function min(a,b:longint):longint;
begin
if a<b then exit(a) else exit(b);
end;
begin
readln(n,m);
for i:=1 to n do
begin
for l:=1 to n do f[i,l]:=maxlongint div 2;
f[i,i]:=0;
end;
for i:=1 to n do
begin
for l:=1 to n do bc[i,l]:=maxlongint div 2+1;
bc[i,i]:=0;
end;
for i:=1 to m do
begin
readln(x,y,c);
inc(o); ne[o]:=be[x];
be[x]:=o; bh[o]:=y; bq[o]:=c;
inc(o); ne[o]:=be[y];
be[y]:=o; bh[o]:=x; bq[o]:=c;
f[x,y]:=min(f[x,y],c); f[y,x]:=f[x,y];
bc[x,y]:=c; bc[y,x]:=c;
end;
for k:=1 to n do
for i:=1 to n do
for l:=1 to n do
if f[i,k]+f[k,l]<f[i,l] then f[i,l]:=f[i,k]+f[k,l];
for kk:=1 to n-1 do
begin
u:=1; p:=1;
for i:=1 to n do sd[i]:=0;
for k:=1 to n do
for i:=1 to n do
if i<>k then
if f[kk,k]+bc[k,i]=f[kk,i] then inc(sd[i]);
for i:=kk+1 to n do
begin
ans:=0;
for l:=1 to n do
if f[kk,l]+f[l,i]=f[kk,i] then ans:=ans+sd[l];
write(ans,' ');
end;
end;
end.