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

WA#6
Posted by Izual 4 Mar 2007 00:49
Sorry for poor english...
I think that this code is true (but it's not topsort!):

const
  INF=2000000000;

var
  a : array [1..100] of integer;
  n,i,j,now,k,min : integer;

begin
  read(n);
  for i:=1 to n do
    a[i]:=i;
  for i:=1 to n do begin
    read(k);
    min:=INF;
    while k<>0 do begin
      for j:=1 to n do
        if (a[j]=k) and (min>j) then
          min:=j;
      read(k);
    end;
    if min<>INF then begin
      for j:=1 to n do
        if a[j]=i then
          now:=j;
      if now>min then begin
        for j:=now downto min+1 do
          a[j]:=a[j-1];
        a[min]:=i;
      end;
    end;
  end;
  write(a[1]);
  for i:=2 to n do
    write(' ',a[i]);
end.

May you give me some bad for my algorithm tests? Thanks for your attention.

Edited by author 04.03.2007 00:54

Edited by author 04.03.2007 00:55