I try this both on pascal and delphi ,but still CRAsh,please help!
program p1096;
var n,m,x,s:integer;
a:array[1..1000,1..2] of integer;
b:array[1..1000,1..4] of integer;
procedure init;
var i:integer;
begin
readln(n);
for i:=1 to n do read(a[i,1],a[i,2]);
read(m,b[1,1],b[1,2]);
if (m=b[1,1])or(m=b[1,2]) then
begin
writeln(0);
halt;
end;
end;
procedure print(p:integer);
var i:integer;
begin
for i:=1 to x do if i=b[p,4] then
begin
inc(s);
print(i);
end;
if b[p,4]=-1 then writeln(s);
writeln(b[p,3]);
end;
procedure solve;
var i,j:integer;
out:boolean;
begin
out:=false;i:=1;x:=1;
while (not(out))and(i<=x) do
begin
for j:=1 to n do if j<>b[i,3] then
if (b[i,1]=a[j,1])or
(b[i,1]=a[j,2])or
(b[i,2]=a[j,1])or
(b[i,2]=a[j,2]) then
begin
inc(x);
b[x,1]:=a[j,1];
b[x,2]:=a[j,2];
b[x,3]:=j;
if b[i,4]=0 then b[x,4]:=-1
else b[x,4]:=i;
if (b[x,1]=m)or(b[x,2]=m) then
begin
out:=true;
break;
end;
end;
inc(i);
end;
s:=1;
if out then print(x)
else writeln('IMPOSSIBLE');
end;
begin
init;
solve;
end.