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

Don't warry! There is AC program here! But I don't know why you cannot do it yourself!!!!!!!!!!!!
Posted by NoFate 12 Jan 2003 13:40
program gen;
const max_n=100;
type people=0..max_n+1;
     data=array[1..max_n,0..max_n]of people;
     deep=array[1..max_n]of people;

var n:people;
    mars:data;
    children:deep;

procedure in_data;
var counter,i,temp:people;
begin
   fillchar(children,sizeof(children),0); counter:=0;
   readln(n);
   for i:=1 to n do
      begin
         read(temp);
         while temp<>0 do
              begin
                 inc(counter);
                 mars[i,counter]:=temp;
                 inc(children[temp]);
                 read(temp);
              end;
         mars[i,0]:=counter;
         counter:=0;
         readln;
      end;
end;

procedure out_data;
var i,j:people;
    ok:boolean;
begin
   ok:=true;
   while ok do
        begin
           ok:=false;
           for i:=1 to n do
              if children[i]=0 then
                begin
                   ok:=true;
                   write(i,' ');
                   children[i]:=max_n+1;
                   for j:=1 to mars[i,0] do
                      dec(children[mars[i,j]]);
                end;
        end;
   writeln;
end;

begin
   in_data;
   out_data;
end.