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 1124. Mosaic

why I got TL
Posted by ACer 13 Aug 2003 09:25
var  n,m,i,j,t,s:longint;
     a:array[0..100,0..100]of longint;

     l:boolean;
procedure done(dep:longint);
var k:longint;
begin
     for k:=1 to n do
         if a[dep,k]>0 then begin
            inc(s);
            dec(a[dep,k]);
            dec(a[dep,0]);
            done(k);
            end;
end;
begin
     read(n);
     read(m);
     for i:=1 to n do
         for j:=1 to m do
         begin
              read(t);
              if t<>I then begin inc(a[i,t]);inc(a[i,0]);end;

              end;

     l:=false;
     for i:=1 to n do

          if a[i,0]>0 then begin
             for j:=1 to n do
                 if a[i,j]>0 then begin
                    inc(s);
                    dec(a[i,j]);
                    dec(a[i,0]);
                    done(j);
                    end;
                    inc(s);
                    l:=true;
                    end;
     if l then s:=s-1;
     writeln(s);
end.


Re: who can me a hint!!!
Posted by ACer 14 Aug 2003 09:40
> var  n,m,i,j,t,s:longint;
>      a:array[0..100,0..100]of longint;
>
>      l:boolean;
> procedure done(dep:longint);
> var k:longint;
> begin
>      for k:=1 to n do
>          if a[dep,k]>0 then begin
>             inc(s);
>             dec(a[dep,k]);
>             dec(a[dep,0]);
>             done(k);
>             end;
> end;
> begin
>      read(n);
>      read(m);
>      for i:=1 to n do
>          for j:=1 to m do
>          begin
>               read(t);
>               if t<>I then begin inc(a[i,t]);inc(a[i,0]);end;
>
>               end;
>
>      l:=false;
>      for i:=1 to n do
>
>           if a[i,0]>0 then begin
>              for j:=1 to n do
>                  if a[i,j]>0 then begin
>                     inc(s);
>                     dec(a[i,j]);
>                     dec(a[i,0]);
>                     done(j);
>                     end;
>                     inc(s);
>                     l:=true;
>                     end;
>      if l then s:=s-1;
>      writeln(s);
> end.
>
>
>
>