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

Why so complicated!!!!!
Posted by Juri Krainjukov 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.
That problem is very easy i don't know why u publish such solution :) (-)
Posted by Miguel Angel 29 Nov 2002 07:08
> 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.
So give shorter solution :-)
Posted by Juri Krainjukov 30 Nov 2002 19:34
if you shorter solution,please, post it here. I just don't know how
to make it smaller.
I just told you "this problem is easy", my solution is equals "in length" to yours, the difference is that i solved this one a lot of time before :) (-)
Posted by Miguel Angel 1 Dec 2002 02:03
> if you shorter solution,please, post it here. I just don't know how
> to make it smaller.
I think If I started solving problems from this site earlier than several weeks ago I would also have already solved it :-)
Posted by Juri Krainjukov 1 Dec 2002 03:12
Yeah, but my point is that this webboard is for questions only :| (-)
Posted by Miguel Angel 1 Dec 2002 05:19
>