|  | 
|  | 
| back to board | Why I get WA? Pelase, help me!!!!!!! (+) My program:
 Program t1124;
 
 Var M,N,i,j,k,a,t  :integer;
 c,s,u          :array[1..500]of integer;
 
 begin
 a:=0;
 for i:=1 to 500 do c[i]:=i;
 for i:=1 to 500 do s[i]:=0;
 for i:=1 to 500 do u[i]:=-1;
 read(m,n);
 for i:=1 to m do
 for j:=1 to n do begin
 read(k);
 if k<>i then begin
 a:=a+1;
 s[k]:=s[k]+1;
 for t:=1 to m do
 if c[t]=k then
 c[t]:=i;
 end;
 end;
 t:=0;
 for i:=1 to m do if s[i]>0 then begin
 if u[c[i]]=-1 then u[c[i]]:=0;
 if s[i] mod 2=1 then u[c[i]]:=u[c[i]]+1;
 end;
 for i:=1 to m do
 if u[i]<>-1 then
 if (u[i]=0)or(u[i]=2) then t:=t+1 else t:=t+(u[i] div 2);
 if t>0 then t:=t-1;
 writeln(a+t);
 end.
A test for you. (+) 3 31 2 2
 2 3 3
 3 1 1
 The answer should be 6, not 7.
 
 Good luck.
Re: Still WA(+) > 3 3> 1 2 2
 > 2 3 3
 > 3 1 1
 > The answer should be 6, not 7.
 >
 > Good luck.
 My new program:
 Program t1124;
 
 Var M,N,i,j,k,a,t  :integer;
 c,s,u          :array[1..500]of integer;
 
 begin
 a:=0;
 for i:=1 to 500 do c[i]:=i;
 for i:=1 to 500 do s[i]:=0;
 for i:=1 to 500 do u[i]:=-1;
 read(m,n);
 for i:=1 to m do
 for j:=1 to n do begin
 read(k);
 if k<>i then begin
 a:=a+1;
 s[k]:=s[k]+1;
 for t:=1 to m do
 if c[t]=c[k] then
 c[t]:=c[i];
 end;
 end;
 t:=0;
 {for i:=1 to m do if s[i]>0 then begin
 if u[c[i]]=-1 then u[c[i]]:=0;
 if s[i] mod 2=1 then u[c[i]]:=u[c[i]]+1;
 end;
 for i:=1 to m do
 if u[i]<>-1 then
 if (u[i]=0)or(u[i]=2) then t:=t+1 else t:=t+(u[i] div 2);}
 for i:=1 to m do begin
 if c[i]<>0 then t:=t+1;
 for j:=i+1 to m do
 if c[j]=c[i] then
 c[j]:=0;
 end;
 if t>0 then t:=t-1;
 writeln(a+t);
 end.
Another test for you (+) 2 11
 2
 
 The answer is 0.
 
 Good luck!
Re:Still WA(+) Pleae help me! Thank for you help!But I still get WA!.I don't know what's wrong.I have 2 programs. But they both wrong!!!. Please, help me!!!
 May be my algorithm is wrong??!
 \\\\\\\Program I:
 
 Program t1124;
 
 Var M,N,i,j,k,a,t  :integer;
 c,s,u          :array[1..500]of integer;
 
 begin
 a:=0;
 for i:=1 to 500 do c[i]:=i;
 for i:=1 to 500 do s[i]:=0;
 for i:=1 to 500 do u[i]:=-1;
 read(m,n);
 for i:=1 to m do
 for j:=1 to n do begin
 read(k);
 if k<>i then begin
 a:=a+1;
 s[k]:=s[k]+1;
 for t:=1 to m do
 if c[t]=c[k] then
 c[t]:=c[i];
 end;
 end;
 t:=0;
 for i:=1 to m do if s[i]>0 then begin
 if u[c[i]]=-1 then u[c[i]]:=0;
 if s[i] mod 2=1 then u[c[i]]:=u[c[i]]+1;
 end;
 for i:=1 to m do begin
 if (c[i]<>0)and(s[i]<>0) then t:=t+1;
 for j:=i+1 to m do
 if c[j]=c[i] then
 c[j]:=0;
 end;
 if t>0 then t:=t-1;
 writeln(a+t);
 end.
 \\\\\\\\Program II:
 
 Program t1124;
 
 Var M,N,i,j,k,a,t  :integer;
 c,s,u          :array[1..500]of integer;
 
 begin
 a:=0;
 for i:=1 to 500 do c[i]:=i;
 for i:=1 to 500 do s[i]:=0;
 for i:=1 to 500 do u[i]:=-1;
 read(m,n);
 for i:=1 to m do
 for j:=1 to n do begin
 read(k);
 if k<>i then begin
 a:=a+1;
 s[k]:=s[k]+1;
 for t:=1 to m do
 if c[t]=c[k] then
 c[t]:=c[i];
 end;
 end;
 t:=0;
 for i:=1 to m do if s[i]>0 then begin
 if u[c[i]]=-1 then u[c[i]]:=0;
 if s[i] mod 2=1 then u[c[i]]:=u[c[i]]+1;
 end;
 for i:=1 to m do
 if u[i]<>-1 then
 if (u[i]=0)or(u[i]=2) then t:=t+1 else t:=t+(u[i] div 2);
 if t>0 then t:=t-1;
 writeln(a+t);
 end.
Re: Re:Still WA(+) Pleae help me! My method is similar with yours. I have WA#13. my prog passed all tests that i had.I can't find my mistake. can anyone give me some tricky tests for this problem? | 
 | 
|