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 1136. Parliament

why crash?
Posted by zealot 17 Nov 2002 12:44
my program here:

program tree_bianli;
const max=30000;
type arr0=record
          data:longint;
          lchild,rchild:longint;
          end;
var t:array[0..max] of arr0;
    i,n,num:longint;
    w:array[0..max] of longint;
    f:array[0..60000] of longint;
procedure readdata;
var i,j,y:longint;
begin
readln(n);
for i:=1 to n do
 begin
  read(t[i].data);
  f[t[i].data]:=i;
 end;
end;
procedure find(f,r,m:longint);
var i:longint;
begin
i:=f;
while t[i].data<t[m].data do inc(i);
dec(i);
if i>=f then t[m].lchild:=t[i].data;
if r-1>=i then t[m].rchild:=t[r].data;
if i>f then find(f,i-1,i);
if r-1>i then find(i+1,r-1,r);
end;
procedure print(p:longint);
begin
if t[p].rchild<>0 then print(f[t[p].rchild]);
if t[p].lchild<>0 then print(f[t[p].lchild]);
inc(num);w[num]:=t[p].data;
end;
BEGIN
readdata;
find(1,n-1,n);
print(n);
for i:=1 to num-1 do write(w[i],' ');writeln(w[num]);
END.
Re: why crash?
Posted by Илья Гофман (Ilya Gofman) 17 Nov 2002 19:37
I think you go out of the array somewhere. Check it with N=30000.