Cod sursa(job #46524)

Utilizator dascaluDascalu Andi-Florin dascalu Data 2 aprilie 2007 18:34:00
Problema Triplete Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.68 kb
{triplete}

const b=16;
      max=512;

var x:array[1..max,1..max div b] of word;
    t:word;
    m,n,i,j,total,pas,p1,p2:integer;
    f:text;


begin
assign(f,'triplete.in'); reset(f);
 readln(f,n,m);
 pas:=n div b;
     if n mod b<>0 then
        inc(pas);

 total:=0;
 for i:=1 to m do begin
     readln(f,p1,p2);
     for j:=1 to pas do begin
         t:=x[p1,j] and x[p2,j];
         while t <> 0 do begin
         t:= (t and (t-1));
         inc(total);
         end;
     end;
     t:=(p2 div b) +1;
     x[p1,t]:=x[p1,t] or (1 shl (p2 mod b));
     t:=(p1 div b) +1;
     x[p2,t]:=x[p2,t] or (1 shl (p1 mod b));
 end;
writeln(total);

close(f);
end.