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 1282. Game Tree

What's wrong with my codes?It WA at 8
Posted by Little Murphy 4 May 2004 09:09
var
  f,q,be:array[0..1000] of integer;
  n,x,a,b,c:integer;
  m:char;
begin
{assign(input,'1282.txt');
reset(input);
}  readln(n);
  for x:=1 to n do
    be[x]:=-3;
  for x:=2 to n do
    begin
      read(m);
      if m='L' then
        begin
          readln(a,b);
          if be[a]=-3 then
            begin
              inc(c);
              q[c]:=a;
              be[a]:=-1;
            end;
          if b=-1 then be[a]:=1;
          if (b=0) and (be[a]<0) then be[a]:=0;
        end
      else
        readln(f[x]);
    end;
  b:=1;
  while q[b]<>1 do
    begin
      if be[f[q[b]]]<-2 then
        begin
          inc(c);
          q[c]:=f[q[b]];
          be[f[q[b]]]:=-1;
        end;
      if be[q[b]]=-1 then be[f[q[b]]]:=1;
      if (be[q[b]]=0) and (be[f[q[b]]]<0) then be[f[q[b]]]:=0;
      inc(b);
    end;
  if be[1]=1 then writeln('+1') else writeln(be[1]);
end.
{be[n]==the best value it then player play best
f[n]==the father of n
be[n]=-3===>it hasn't been visited
}
Maybe you have misunderstood it......
Posted by Neumann 8 Feb 2005 17:46
Read these sentences carefully:
  The leaf nodes of the tree of this game may have values equal to one of three numbers: “+1” – victory of the first competitor, “–1” – victory of the second competitor, “0” – draw.

For example,

Input
3
L 1 +1
L 1 +1
Output
+1

Input
3
L 1 +1
L 1 -1
Output
+1

Input
3
L 1 -1
L 1 -1
Output
-1

Hope it can help:)