what a kind of test that make me WA. this is my code. / and what about if n=0,1,2
Posted by
Badd 22 Jan 2002 15:32
const inp = '1128.in';
maxdat = 1000;
var fname : text;
dat : array[1..maxdat,1..3] of integer;
ndat : array[1..maxdat] of byte;
col : array[1..maxdat] of byte;
n,check,l,l2 : longint;
procedure out;
var loop,count,temp : longint;
begin
count:=0;
for loop:=1 to n do
if col[loop]=1 then inc(count);
if count>n div 2 then temp:=2
else temp:=1;
if temp=1 then begin if count=n then begin writeln(1); writeln(1);
halt; end;
writeln(count)
end
else if n-count>0 then writeln(n-count) else
begin
if count=n then begin writeln(1); writeln(1); halt; end;
writeln(count);
end;
if n-count=0 then temp:=1;
for loop:=1 to n do
if col[loop]=temp then write(loop,' ');
writeln;
halt;
end;
procedure process(now,ccc : longint);
var loop,count,temp,gain : longint;
begin
col[now]:=ccc;
for loop:=1 to ndat[now] do
if col[dat[now,loop]]=0 then
process(dat[now,loop],(ccc mod 2)+1);
end;
procedure swap;
var l,l2,count : longint;
begin
for l:=1 to n do
begin
count:=0;
for l2:=1 to ndat[l] do
if col[dat[l,l2]]=col[l] then inc(count);
if count>1 then
begin
count:=0;
for l2:=1 to ndat[l] do
if col[dat[l,l2]]=(col[l] mod 2)+1 then inc(count);
if count>1 then begin writeln('NO SOLUTION'); halt; end
else col[l]:=(col[l] mod 2)+1;
end;
end;
end;
begin
fillchar(ndat,sizeof(ndat),0);
fillchar(col,sizeof(col),0);
readln(n);
for l:=1 to n do
begin
read(ndat[l]);
for l2:=1 to ndat[l] do
read(dat[l,l2]);
readln;
end;
if n=0 then begin writeln(0); halt; end;
if n=2 then begin writeln(1); writeln(1); halt; end;
check:=0;
for l:=1 to n do
if col[l]=0 then
process(l,1);
swap;
out;
end.