Pagini recente » Cod sursa (job #2719337) | Cod sursa (job #1855919) | Cod sursa (job #1312876) | Cod sursa (job #2267591) | Cod sursa (job #296687)
Cod sursa(job #296687)
type rec=record
a,b,c:longint;
end;
var i,j,n,ls,poz:longint;
p:array[1..5000] of rec;
s,h,sol:array[0..5000] of longint;
procedure sort(x:longint);
var aux:longint;
begin
if p[i].a>p[i].b then
begin
aux:=p[i].a; p[i].a:=p[i].b; p[i].b:=aux;
end;
if p[i].a>p[i].c then
begin
aux:=p[i].a; p[i].a:=p[i].c; p[i].c:=aux;
end;
if p[i].b>p[i].c then
begin
aux:=p[i].b; p[i].b:=p[i].c; p[i].c:=aux;
end;
end;
procedure diferite;
begin
for j:=poz-1 downto p[poz].b+1 do sol[j]:=sol[j-1];
sol[p[poz].b]:=poz-1;
for j:=poz downto p[poz].c+1 do sol[j]:=sol[j-1];
sol[p[poz].c]:=poz;
end;
procedure egale;
begin
for j:=poz downto p[poz].b+1 do sol[j]:=sol[j-1];
sol[p[poz].b]:=poz;
end;
begin
assign(input,'sortare.in'); reset(input);
assign(output,'sortare.out'); rewrite(output);
readln(n);
for i:=2 to n do begin readln(p[i].a,p[i].b,p[i].c); sort(i);end;
h[0]:=0; h[1]:=1;
for i:=2 to n do
begin
if (p[i].a=p[i].b)and(p[i].b=p[i].c) then h[i]:=h[i-1]+1
else if (p[i].a=p[i].b)or(p[i].b=p[i].c) then h[i]:=h[i-1]+1
else h[i]:=h[i-2]+1;
end;
writeln(h[n]);
s[1]:=n;
ls:=1;
while s[ls]>1 do
begin
i:=s[ls];
if (p[i].a<p[i].b)and(p[i].b<p[i].c) then
begin
inc(ls);
s[ls]:=i-2;
end
else
begin
inc(ls);
s[ls]:=i-1;
end;
end;
for i:=ls downto 1 do
begin
poz:=s[i];
if poz=1 then sol[1]:=1
else
begin
if (p[poz].a<>p[poz].b)and(p[poz].b<>p[poz].c) then diferite
else egale;
end;
end;
for i:=1 to n do write(sol[i],' ');
close(output);
close(input);
end.