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

Please give me some test
Posted by Harmy 25 May 2004 11:53
{my wrong code}
const
  maxn=600;
type
  link=^re;
  re=record
    num:integer;
    q:link;
  end;
var
  p:link;
  n:longint;
  va:array[1..maxn]of byte;
  g:array[1..maxn]of link;
  max:array[1..maxn,0..1]of longint;
  r:array[1..maxn]of boolean;

  procedure init;
  var
    x,y,i:longint;
  begin
    assign(input,'1039.in'); reset(Input);
    fillchar(r,sizeof(r),false);
    readln(n);
    for i:=1 to n do
      readln(va[i]);
    readln(y,x);
    while (x<>0) or (y<>0) do
    begin
      r[y]:=true;
      new(p);
      p^.num:=y;
      p^.q:=g[x];
      g[x]:=p;
      readln(y,x);
    end;
  end;

  procedure solve(root:longint);
  var
    p:link;
    x,big:longint;
  begin
    new(p); p:=g[root];
    while p<>nil do
    begin
      x:=p^.num;
      solve(x);
      inc(max[root,1],max[x,0]);
      if max[x,0]>max[x,1]
        then big:=max[x,0]
        else big:=max[x,1];
      inc(max[root,0],big);
      p:=p^.q;
    end;
    inc(max[root,1],va[root]);
  end;

  procedure main;
  var
    i:longint;
  begin
    for i:=1 to n do
      if not(r[i])
        then begin
          solve(i);
          if max[i,1]>max[i,0]
            then writeln(max[i,1])
            else writeln(max[i,0]);
          exit;
        end;
  end;

begin
  init;
  main;
end.


The code is wrong at the fourth test.I am pluzzled.
Please give me some tests. Sorry for my fool.











Two bugs
Posted by Vlad Veselov 25 May 2004 15:25
1). maxn must be 6000
2). va must be array of LongInt
Re: Two bugs
Posted by Harmy 26 May 2004 13:30
    Thank you very much!
    I fix my code following your advice and AC now.
I am so careless that I feel very ashamed.You are an alive
Lei Feng(a great person).And I would like to make friends
with you.
Re: Two bugs
Posted by Maigo Akisame 10 Jun 2004 04:06
'An alive Lei Feng' is wrong, it must be 'a living Lei Feng'.