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 1045. Funny Game

Please help me WA again !!! &-(
Posted by Saber 28 Feb 2003 17:00
here is my code please help me ...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var
  n,k,j,k1,k2   : integer;
  a             : array [1..1000,1..1000] of integer;
  lab           : array [1..1000] of boolean;
  win           : array [1..1000] of integer;
  find          : boolean;
procedure dfs(w,w1:integer);
var
  i             : integer;
  f,f1           : boolean;
begin
  f:=false;lab[w]:=true;
  for i:=1 to n do
    if not lab[i] and (a[i,w]>0) then
    begin
        dfs(i,3-w1);
        f:=true;
    end;
  if not f then
    win[w]:=2
  else
    begin
      f1:=false;
      for i:=1 to n do
        if (a[i,w]>0) and (win[i]=3-w1) then f1:=true;
      if f1 then win[w]:=w1 else win[w]:=3-w1;
    end;
end;
begin
 find:=false;
  fillchar(lab,sizeof(lab),False);
  fillchar(win,sizeof(win),0);
  readln(n,k);
  for j:=1 to n-1 do
    begin
      read(k1,k2);
      a[k1,k2]:=1;
      a[k2,k1]:=1;
    end;
  dfs(k,1);
  for k1:=1 to n do
    if (a[k1,k]=1) and (win[k1]=2) then
      begin
        find:=true;
        writeln('First player wins flying to airport ',k1);
        break;
      end;
  if not find then
    writeln('First player loses');
end.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Here is new one , but still WA :((
Posted by Saber 3 Mar 2003 15:24
Program funny;
var
  n,k,k1,k2,k3: integer;
  f           : boolean;
  a           : array[1..1000,0..20] of integer;
  win         : array[1..1000] of byte;
procedure dfs(w:integer);
var
  i           : integer;
begin
  if a[w,0]=0 then
    begin
      win[w]:=1;
      exit;
    end
  else
    begin
      for i:=1 to a[w,0] do
        dfs(a[w,i]);
      win[w]:=1;
      for i:=1 to a[w,0] do
        if win[a[w,i]]=1 then
          win[w]:=2;
    end;
end;
begin
  readln(n,k);
  for k1:=1 to n-1 do
    begin
      readln(k2,k3);
      inc(a[k2,0]);
      a[k2,a[k2,0]]:=k3;
    end;
  dfs(k);k2:=10001;f:=false;
  for k1:=1 to a[k,0] do
    if win[a[k,k1]]=1 then
      begin
        f:=true;
        if a[k,k1]<k2 then k2:=a[k,k1];
      end;
  if f then
    writeln('First player wins flying to airport ',k2)
  else
    writeln('First player loses');
end.
I get AC but donno my prev prog bug ...
Posted by Saber 12 Apr 2003 16:08
> Program funny;
> var
>   n,k,k1,k2,k3: integer;
>   f           : boolean;
>   a           : array[1..1000,0..20] of integer;
>   win         : array[1..1000] of byte;
> procedure dfs(w:integer);
> var
>   i           : integer;
> begin
>   if a[w,0]=0 then
>     begin
>       win[w]:=1;
>       exit;
>     end
>   else
>     begin
>       for i:=1 to a[w,0] do
>         dfs(a[w,i]);
>       win[w]:=1;
>       for i:=1 to a[w,0] do
>         if win[a[w,i]]=1 then
>           win[w]:=2;
>     end;
> end;
> begin
>   readln(n,k);
>   for k1:=1 to n-1 do
>     begin
>       readln(k2,k3);
>       inc(a[k2,0]);
>       a[k2,a[k2,0]]:=k3;
>     end;
>   dfs(k);k2:=10001;f:=false;
>   for k1:=1 to a[k,0] do
>     if win[a[k,k1]]=1 then
>       begin
>         f:=true;
>         if a[k,k1]<k2 then k2:=a[k,k1];
>       end;
>   if f then
>     writeln('First player wins flying to airport ',k2)
>   else
>     writeln('First player loses');
> end.