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

Common Board

What's wrong with my program? Please,help me!!! Problem 1124.
Posted by Nazarov Denis (nsc2001@rambler.ru) 14 Jan 2002 20:21
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.