var i,n,j,k,t:longint;a:array[1..20,1..20]of longint; function min(a,b:longint):longint;begin if a<b then exit(a)else exit(b);end; begin t:=0; while not eof do begin t:=t+1; fillchar(a,sizeof(a),$7f); for i:=1 to 19 do begin read(n); for j:=1 to n do begin read(k); a[i,k]:=1; a[k,i]:=1; end; readln; end; for k:=1 to 20 do for i:=1 to 20 do if(i<>k)and(a[i,k]<$7f)then for j:=1 to 20 do if(k<>j)and(a[k,j]<$7f)then begin a[i,j]:=min(a[i,k]+a[k,j],a[i,j]); a[j,i]:=a[i,j]; end; readln(n); writeln(‘Test Set #‘,t); for i:=1 to n do begin readln(j,k); writeln(j:2,‘ to ‘,k:2,‘:‘,a[j,k]:2); end; writeln; end; end.
时间: 2024-10-05 00:31:47