此题简单最小环,用来练练手
最小环如下:
const maxnum=16843009;
var
n,m,r:longint;
map,f:array[0..100,0..100]of longint;
procedure main;
var
i,a,k,j,b,c:longint;
begin
readln(n,m);
fillchar(map,sizeof(map),1);
for i:=1 to m do
begin
readln(a,b,c);
map[a,b]:=c;
map[b,a]:=c;
end;
for i:=1 to n do map[i,i]:=0;
f:=map;
r:=maxnum;
for k:=1 to n do
begin
for i:=1 to k-1 do
for j:=i+1 to k-1 do
if f[i,j]+map[j,k]+map[k,i]<r then
r:=f[i,j]+map[j,k]+map[k,i];
for i:=1 to n do
for j:=1 to n do
if f[i,j]>f[i,k]+f[k,j] then
f[i,j]:=f[i,k]+f[k,j];
end;
if r<maxnum then writeln(r) else writeln('No solution.');
end;
begin
while not(eof) do main;
end.