I use DFS to solve 1176 and get WA! I can't find test on which my program fails. Please, help me ! ! !(+)
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 ! ! !(+)
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