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

What's wrong with my program?ЈЁWhy Compilation ErrorЈїЈїЈїЈїЈ©
Posted by hongyan 26 Nov 2002 06:02
program abc;
var
i,num,temp,h,k:integer;
sz:array[1..150,1..150] of boolean;
b:array[1..150] of integer;
b1,b2,bj:boolean;

begin
fillchar(sz,sizeof(sz),0);
readln(num);
for i:=1 to num do
    begin
    read(temp);
    while temp<>0 do
          begin
          sz[i,temp]:=true;
          read(temp);
          end;
    readln;
    end;
for k:=1 to num do
begin
b1:=true;h:=1;b[h]:=k;
while b1 do
      begin
      b2:=true;h:=h+1;b[h]:=0;
      while b2 do
            begin
            b[h]:=b[h]+1;
            if b[h]<=num then
               begin
               if sz[b[h-1],b[h]] then
                  begin
                  bj:=true;
                  for i:=1 to h-1 do
                      if b[i]=b[h] then begin bj:=false;i:=h-1;end;
                  if bj then
                     begin
                     if h=num then
                        begin
                        for i:=1 to num do write(b[i]);
                        b2:=false;
                        b1:=b2;
                        k:=num;
                        end
                     else b2:=false;
                     end;
                  end;
               end
            else
                begin
                h:=h-1;
                if h=1 then
                   begin
                   b2:=false;
                   b1:=b2;
                   end;
                end;
            end;
      end;
end;
end.
See your program. But it got TL.
Posted by I am david. Tabo. 26 Nov 2002 15:24
var
i,num,temp,h,k:integer;
sz:array[1..150,1..150] of boolean;
b:array[1..150] of integer;
b1,b2,bj:boolean;

begin
fillchar(sz,sizeof(sz),0);
readln(num);
for i:=1 to num do
    begin
    read(temp);
    while temp<>0 do
          begin
          sz[i,temp]:=true;
          read(temp);
          end;
    readln;
    end;
k:=1;
while k<=num do
begin
  b1:=true;h:=1;b[h]:=k;
  while b1 do
    begin
      b2:=true;
      h:=h+1;
      b[h]:=0;
      while b2 do
        begin
          b[h]:=b[h]+1;
          if b[h]<=num then
            begin
              if sz[b[h-1],b[h]] then
                begin
                  bj:=true;i:=1;
                  while i<=h-1 do
                      if b[i]=b[h] then
                        begin
                          bj:=false;
                          i:=h-1;
                        end;
                  if bj then
                     begin
                     if h=num then
                        begin
                        for i:=1 to num do write(b[i]);
                        b2:=false;
                        b1:=b2;
                        k:=num;
                        end
                     else b2:=false;
                     end;
                  end;
               end
            else
                begin
                h:=h-1;
                if h=1 then
                   begin
                   b2:=false;
                   b1:=b2;
                   end;
                end;
            end;
      end;
end;
end.