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 1182. Team Them Up!

I got WA!Why?Who can help me?Thank you!
Posted by New CD 19 Dec 2002 18:14
program ti;
var can,n,i,j:longint;
    p:boolean;
    cc:array[1..2]of integer;
    t1,t2:array[1..100]of integer;
    a:array[1..100,1..100]of boolean;

begin
     fillchar(a,sizeof(a),false);
     readln(n);
     for i:=1 to n do begin
         read(j);
         while j<>0 do begin
               a[i,j]:=true;
               read(j);
         end;
         readln;
     end;
     fillchar(t1,sizeof(t1),0);
     fillchar(t2,sizeof(t2),0);
     t1[1]:=1;
     cc[1]:=1; cc[2]:=0;
     can:=0;
     for i:=2 to n do begin
         p:=true;
         for j:=1 to cc[1] do if not((a[i,t1[j]])and(a[t1[j],i]))
then begin
             p:=false;
             break;
         end;
         if p then begin
            cc[1]:=cc[1]+1;
            t1[cc[1]]:=i;
         end else begin
             p:=true;
             for j:=1 to cc[2] do if not((a[i,t2[j]])and(a[t2
[j],i])) then begin
                 p:=false;
                 break;
             end;
             if p then begin
                cc[2]:=cc[2]+1;
                t2[cc[2]]:=i;
             end else begin
                 can:=1;
                 break;
             end;
         end;
     end;
     if (can=1) then begin
        write('No solution');
        halt;
     end;
     can:=cc[1];
     if cc[1]-cc[2]>1 then begin
        for i:=1 to cc[1] do begin
            p:=true;
            for j:=1 to cc[2] do if not((a[t1[i],t2[j]])and(a[t2
[j],t1[i]])) then begin
                p:=false;
                break;
            end;
            if p then begin
               cc[2]:=cc[2]+1;
               t2[cc[2]]:=t1[i];
               t1[i]:=0;
               can:=can-1;
               if can-cc[2]<=1 then break;
            end;
        end;
     end;
     write(can);
     for i:=1 to cc[1] do if t1[i]<>0 then write(' ',t1[i]);
     writeln;
     write(cc[2]);
     for i:=1 to cc[2] do write(' ',t2[i]);
end.