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

Common Board

I use DFS to solve 1176 and get WA! I can't find test on which my program fails. Please, help me ! ! !(+)
Posted by Nazarov Denis (nsc2001@rambler.ru) 16 Feb 2002 22:17
Program t1176;

Const MaxN = 1000;

Type  Mas  = array[1..MaxN,1..MaxN div 2]of byte;

Var   G        : Mas;
      N,A,i,j  : longint;
      Cur      : longint;
      Path     : array[1..MaxN*10]of integer;
      b        : byte;
      label    New,ENew;

Function GetV(i,j : integer) : byte;
var t,s,fi,se : integer;
 begin
  s:=(j div 2)+(j mod 2);
  t:=g[i,s];
  fi:=t mod 2;
  se:=(t-fi) div 2;
  if j mod 2=0 then GetV:=fi else GetV:=se;
 end;

Procedure SetV(i,j : integer;v : byte);
var t,s,fi,se : integer;
 begin
  s:=(j div 2)+(j mod 2);
  t:=g[i,s];
  fi:=t mod 2;
  se:=(t-fi) div 2;
  if j mod 2=0 then fi:=v else se:=v;
  g[i,s]:=fi+se*2;
 end;

begin
 Read(N,A);
 for i:=1 to N do
  for j:=1 to N do begin
    read(b);
    SetV(i,j,b);
   end;
 for i:=1 to N do SetV(i,i,1);
 Path[1]:=A;
 Cur:=1;
New:
  Cur:=Cur+1;
  for i:=1 to N do
    if (GetV(Path[Cur-1],i)=0)or(GetV(i,Path[Cur-1])=0) then begin
     Path[Cur]:=i;
     SetV(i,Path[Cur-1],1);
     SetV(Path[Cur-1],i,1);
     Writeln(Path[Cur-1],' ',Path[Cur]);
     goto New;
    end;
  Cur:=Cur-2;
  if Cur=0 then goto ENew;
  Writeln(Path[Cur+1],' ',Path[Cur]);
  goto New;
ENew:
end.
Re: I use DFS to solve 1176 and get WA! I can't find test on which my program fails. Please, help me ! ! !(+)
Posted by Mephistos 17 Feb 2002 09:56
7 1
1 0 1 1 1 1 1
1 1 0 1 0 1 1
1 1 1 0 1 1 1
0 1 1 1 1 1 1
1 1 1 1 1 0 1
1 1 1 1 1 1 0
1 0 1 1 1 1 1