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 1109. Conference

Why I get WA? Pelase, help me!!!!!!! (+)
Posted by Nazarov Denis (nsc2001@rambler.ru) 24 Jan 2002 16:40
My code:

Program t1109;

Const MaxN=1000;
      MaxK=500000;

Var   A,B       :array[1..MaxN]of integer;
      AU,BU     :array[1..MaxN]of integer;
      Ver       :array[1..MaxK,1..2]of integer;
      M,N,K,i   :integer;
      Mi,Ni     :integer;
      Ans       :integer;
      ex        :boolean;

Function Max(A,B:integer):integer;
 begin
  If A>B then Max:=A else Max:=B;
 end;

begin
 FillChar(A,SizeOf(A),0);
 FillChar(B,SizeOf(B),0);
 FillChar(AU,SizeOf(AU),0);
 FillChar(BU,SizeOf(BU),0);
 Read(N,M,K);
 for i:=1 to K do begin
   read(ver[i,1],ver[i,2]);
   inc(a[ver[i,1]]);
   inc(b[ver[i,2]]);
  end;
 Ans:=0;
 Ni:=N;
 Mi:=M;
 repeat
 ex:=true;
 for i:=1 to K do
  if a[ver[i,1]]=1 then
   if AU[ver[i,1]]=0 then begin
    Ans:=Ans+1;
    if BU[ver[i,2]]=0 then dec(Mi);
    BU[ver[i,2]]:=1;
    AU[ver[i,1]]:=1;
    dec(a[ver[i,1]]);
    dec(b[ver[i,2]]);
    dec(Ni);
    ex:=false;
   end;
 for i:=1 to K do
  if AU[ver[i,1]]=1 then
   if BU[ver[i,2]]=0 then begin
    ex:=false;
    if B[ver[i,2]]=1 then begin
      Ans:=Ans+1;
      BU[ver[i,2]]:=1;
      dec(Mi);
     end;
    dec(a[ver[i,1]]);
    dec(b[ver[i,2]]);
   end;
 for i:=1 to K do
  if b[ver[i,2]]=1 then
   if BU[ver[i,2]]=0 then begin
    Ans:=Ans+1;
    if AU[ver[i,1]]=0 then dec(Ni);
    AU[ver[i,1]]:=1;
    BU[ver[i,2]]:=1;
    dec(a[ver[i,1]]);
    dec(b[ver[i,2]]);
    dec(Mi);
    ex:=false;
   end;
 for i:=1 to K do
  if BU[ver[i,2]]=1 then
   if AU[ver[i,1]]=0 then begin
    ex:=false;
    if A[ver[i,1]]=1 then begin
      Ans:=Ans+1;
      AU[ver[i,1]]:=1;
      dec(Ni);
     end;
    dec(a[ver[i,1]]);
    dec(b[ver[i,2]]);
   end;
 until ex;
 Ans:=Ans+Max(Mi,Ni);
 Writeln(Ans);
end.
A test for you (+)
Posted by shitty.Mishka 24 Jan 2002 17:33
Try this test case:
5 5 12
1 1
1 2
1 3
2 1
2 4
2 5
3 1
3 2
4 3
4 4
4 5
5 1

The answer of your program is 8, while the correct output is 5.

Hope this will help.

Good luck!
Thank you very much for your help, but my program is incorrect :=((
Posted by Nazarov Denis (nsc2001@rambler.ru) 24 Jan 2002 19:54
> Try this test case:
> 5 5 12
> 1 1
> 1 2
> 1 3
> 2 1
> 2 4
> 2 5
> 3 1
> 3 2
> 4 3
> 4 4
> 4 5
> 5 1
>
> The answer of your program is 8, while the correct output is 5.
>
> Hope this will help.
>
> Good luck!
>
>