ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1022. Genealogical Tree

Juri Krainjukov Why so complicated!!!!! [5] // Problem 1022. Genealogical Tree 29 Nov 2002 01:21
Look at this solution. It's very easy and it works!!!!!!!

var
   n:integer;
   i,j,c:integer;
   a:array[1..100,1..100] of boolean;
   b:array[1..100] of boolean;
   s:array[1..100] of integer;

procedure ds(x:integer);
var
    i:integer;
begin
   b[x]:=false;
   for I:=1 to n do
      if (a[x,i]) and (b[i]) then ds(i);
   dec(c);
   s[c]:=x;
end;

begin
   for I:=1 to 100 do for J:=1 to 100 do a[i,j]:=false;
   for i:=1 to 100 do b[i]:=true;

   readln(n);

   for I:=1 to n do begin
      repeat
          read(c);
         if c<>0 then a[i,c]:=true;
      until c=0
   end;

   c:=n+1;

   for I:=1 to n do if b[i] then ds(i);
   for i:=1 to n do begin
      write(s[i]);
      if i<n then write(' ');
   end;

end.
> Look at this solution. It's very easy and it works!!!!!!!
>
> var
>    n:integer;
>    i,j,c:integer;
>    a:array[1..100,1..100] of boolean;
>    b:array[1..100] of boolean;
>    s:array[1..100] of integer;
>
> procedure ds(x:integer);
> var
>     i:integer;
> begin
>    b[x]:=false;
>    for I:=1 to n do
>       if (a[x,i]) and (b[i]) then ds(i);
>    dec(c);
>    s[c]:=x;
> end;
>
> begin
>    for I:=1 to 100 do for J:=1 to 100 do a[i,j]:=false;
>    for i:=1 to 100 do b[i]:=true;
>
>    readln(n);
>
>    for I:=1 to n do begin
>       repeat
>           read(c);
>          if c<>0 then a[i,c]:=true;
>       until c=0
>    end;
>
>    c:=n+1;
>
>    for I:=1 to n do if b[i] then ds(i);
>    for i:=1 to n do begin
>       write(s[i]);
>       if i<n then write(' ');
>    end;
>
> end.
Juri Krainjukov So give shorter solution :-) [3] // Problem 1022. Genealogical Tree 30 Nov 2002 19:34
if you shorter solution,please, post it here. I just don't know how
to make it smaller.