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 1039. Anniversary Party

help! help!
Posted by hbxfwz 3 Nov 2007 07:32
why? my program compile error???
my program run on FREEPASCAL is correct.
please help me!!!!

program ural1039;
  type
    n1=record
            ld,rd,p,d:integer;
          end;
  var
    tr:array[1..6000] of n1;
    v:array[1..6000] of boolean;
    f,g:array[1..6000] of longint;
    i,n,l,k,temp,root:integer;
  function max(x,y:longint):longint;
    begin
      max:=x;
      if max<y then max:=y;
    end;
  procedure treedp(i1:integer);
    var
      sum1,sum2:longint;
      t:integer;
    begin
      if v[i1] then exit;
      sum1:=tr[i1].d;
      sum2:=0;
      treedp(tr[i1].ld);
      sum1:=sum1+g[tr[i1].ld];
      sum2:=sum2+max(f[tr[i1].ld],g[tr[i1].ld]);
      t:=tr[tr[i1].ld].rd;
      while t<>0 do
        begin
          treedp(t);
          sum1:=sum1+g[t];
          sum2:=sum2+max(f[t],g[t]);
          t:=tr[t].rd;
        end;

      f[i1]:=sum1;
      g[i1]:=sum2;
      v[i1]:=true;
    end;
  begin
    readln(n);
    for i:=1 to n do
      begin
        f[i]:=0;
        g[i]:=0;
        v[i]:=false;
        tr[i].ld:=0;
        tr[i].rd:=0;
        tr[i].p:=0;
        tr[i].d:=0;
      end;
    for i:=1 to n do
      readln(tr[i].d);
    readln(l,k);
    repeat
      tr[l].p:=k;
      if tr[k].ld=0 then tr[k].ld:=l
                      else begin
                             temp:=tr[k].ld;
                             while tr[temp].rd<>0 do
                               temp:=tr[temp].rd;
                             tr[temp].rd:=l;
                           end;
      readln(l,k);
    until(l=0) and (k=0);
    for i:=1 to n do
      if tr[i].p=0 then begin
                            root:=i;
                            break;
                          end;
    for i:=1 to n do
      if tr[i].ld=0 then
        begin
          f[i]:=tr[i].d;
          g[i]:=0;
          v[i]:=true;
        end;
    treedp(root);
    writeln(max(f[root],g[root]));
  end.