O,God! I'll go mad! Who can help me and give me some tests,I'll be grateful.(+)
Послано
sunoi 25 окт 2004 09:54
type arr=array[1..500,1..5] of integer;
ar=array[1..500] of boolean;
var a:arr;
d:ar;
i,j,maxcode,max,n:integer;
function init(i,j:integer):boolean;
begin
if (a[i,1]>a[j,1]) and (a[i,2]<a[j,2]) then init:=true
else init:=false;
end;
procedure search(x:integer);
var i,j,m,mcode:integer;
begin
m:=0;mcode:=0;
for i:=1 to n do
begin
if init(i,x) then
begin
if d[i] then search(i);
if a[i,3]>m then begin m:=a[i,3];mcode:=i;end;
end;
end;
a[x,3]:=m+1;
a[x,4]:=mcode;
d[x]:=false;
end;
procedure printa(i:integer);
begin
if a[i,4]<>0 then printa(a[i,4]);
if i=maxcode then writeln(i)
else write(i,' ');
end;
begin
fillchar(d,sizeof(d),true);
fillchar(a,sizeof(a),0);
readln(n);
if n=0 then begin writeln(0);halt;end;
for i:=1 to n do
begin
readln(a[i,1],a[i,2]);
if a[i,1]>a[i,2] then begin j:=a[i,1];a[i,1]:=a[i,2];a[i,2]:=j;end;
a[i,3]:=1;
end;
max:=0;maxcode:=0;
for i:=1 to n do
begin
if d[i] then search(i);
if a[i,3]>maxcode then begin max:=a[i,3];maxcode:=i;end;
end;
i:=maxcode;
writeln(max);
printa(maxcode);
end.