ac1055.pas
来自「某牛人写的acm.tongji.edu.cn上大部分ac的代码,仅供学习研究,请」· PAS 代码 · 共 47 行
PAS
47 行
program tju1055;
const
maxn=100;
var
adj:array[1..maxn,1..maxn]of boolean;
v:array[1..maxn]of boolean;
n,x,y,z:byte;
ok:boolean;
procedure floodfill(x:byte);
var
i:byte;
begin
v[x]:=true;
if x=y then exit;
for i:=1 to n do
if not v[i] and adj[x,i] and (i<>z) then begin
floodfill(i);
if v[y] then exit;
end;
end;
begin
repeat
fillchar(adj,sizeof(adj),0);
read(n);
repeat
read(x,y);
if x=0 then break;
adj[x,y]:=true;adj[y,x]:=true;
until false;
read(x,y);
ok:=false;
for z:=1 to n do
if (z<>x) and (z<>y) then begin
fillchar(v,sizeof(v),0);
floodfill(x);
if not v[y] then begin
writeln(z);
ok:=true;
break;
end;
end;
if not ok then writeln('No solution');
until seekeof;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?