ac1189.pas
来自「某牛人写的acm.tongji.edu.cn上大部分ac的代码,仅供学习研究,请」· PAS 代码 · 共 33 行
PAS
33 行
program tju1189;
const
maxn=500;
var
adj:array[1..maxn,1..maxn]of boolean;
route,dist,q:array[1..maxn]of word;
m,n,i,j,f,r:word;
begin
repeat
fillchar(adj,sizeof(adj),0);
fillchar(dist,sizeof(dist),255);
read(m,n);
for i:=1 to m do begin
r:=0;
repeat
inc(r);read(route[r]);
for j:=1 to r-1 do
adj[route[j],route[r]]:=true;
until seekeoln;
end;
f:=0;r:=1;q[1]:=1;dist[1]:=0;
repeat
inc(f);
for i:=1 to n do
if adj[q[f],i] and (dist[i]=65535) then begin
inc(r);q[r]:=i;dist[i]:=dist[q[f]]+1;
end;
until (f=r) or (dist[n]<65535);
if f=r then writeln('NO') else writeln(dist[n]-1);
until seekeof;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?