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 1211. Collective Guarantee

What does this poblem mean?I do it like this,but WA
Posted by linchuan 13 Oct 2002 09:00
var t,n,i,j:longint;
    d:array[1..25000] of integer;
    ok:boolean;
begin
 read(t);
 for i:=1 to t do
 begin
  read(n);ok:=false;
  for j:=1 to n do
  begin
   read(d[j]);
   if d[j]=0 then ok:=true;
  end;
  if not ok then writeln('NO')
   else begin
         for j:=1 to n do
          if d[j]<>0 then
           if d[d[j]]=j then begin ok:=false;writeln('NO');break;end;
         if ok then writeln('YES');
        end;
 end;
end.
May be do it like this?
Posted by linchuan 13 Oct 2002 12:29
var t,n,i,j,k:longint;
    d:array[1..25000] of integer;
    p:array[0..3124] of set of 0..7;
    ok:boolean;
begin
 read(t);
 for i:=1 to t do
 begin
  read(n);ok:=false;
  for j:=1 to n do
  begin
   read(d[j]);
   if d[j]=0 then ok:=true;
  end;
  if not ok then writeln('NO')
   else begin
         fillchar(p,sizeof(p),0);
         for j:=1 to n do
          if (d[j]<>0)and not ((j-1) mod 8 in p[(j-1) div 8]) then
          begin
           p[(j-1) div 8]:=p[(j-1) div 8]+[(j-1) mod 8];k:=j;
           repeat
            k:=d[k];
            if (k-1) in p[(k-1) div 8] then
             begin writeln('NO');ok:=false;break;end;
            p[(k-1) div 8]:=p[(k-1) div 8]+[(k-1) mod 8];
           until d[k]=0;
           fillchar(p,sizeof(p),0);
           if not ok then break;
          end;
         if ok then writeln('YES');
        end;
 end;
end.
Re: May be do it like this?
Posted by SES (Igor' Anisutin) 6 Aug 2009 11:23
"if d[j]=0 then ok:=true;"
"...надо записать «YES» если показания детей, по крайней мере, выглядят непротиворечивыми: РОВНО ОДИН ребёнок признался в том, что он разбил кружку..."