|
|
back to boardCommon BoardWhat's wrong with my program? Please,help me!!! Problem 1124. My program: Program t1124; Var M,N,i,j,k,a,t :longint; c,s,u :array[1..500]of longint; 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 j:=1 to m do if u[j]<>-1 then if (u[j]=0)or(u[j]=2) then t:=t+1 else t:=t+(u[j] div 2); if t>0 then t:=t-1; a:=a+t; writeln(a); end. |
|
|