Cod sursa(job #46565)

Utilizator belgun_adrianBelgun Dimitri Adrian belgun_adrian Data 2 aprilie 2007 19:04:22
Problema Triplete Scor 30
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.74 kb
{triplete}

const b=32;
      max=1024;

var x:array[1..max,1..max div b] of longword;
    t:longword;
    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;
 close(f);
 assign(f,'triplete.out'); rewrite(f);
 writeln(f,total);
 close(f);

end.