var b,f:..] of longint; s,t,i,j,n,m,x,y:longint; l,h:..]of longint; a:..,..]of longint; procedure bfs; var i,head,tail,x,y:longint; begin fillchar(b,sizeof(b),); fillchar(h,sizeof(h),$7f); h[t]:=; head:=; tail:=; b[]:=t; while head<=tail do begin x:=…