Cod sursa(job #12676)

Utilizator andreitheo87Teodorescu Andrei-Marius andreitheo87 Data 4 februarie 2007 16:28:54
Problema Triplete Scor 70
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.79 kb
var fi,fo:text;
    i,n,j,x,y,aux:word;
    rez,bla,m:longint;
    xx,yy:array[0..1 shl 16-1]of word;
    nr:array[0..1 shl 16-1]of word;
    mat:array[0..4096,0..4096 div 31]of longint;
begin
 assign(fi,'triplete.in'); reset(fi);
 assign(fo,'triplete.out'); rewrite(fo);
 readln(fi,n,m);
 for i:=0 to m-1 do
  begin
        readln(fi,x,y);
        mat[x,y div 31]:=mat[x,y div 31]or (1 shl(y mod 31));
        mat[y,x div 31]:=mat[y,x div 31]or (1 shl(x mod 31));
        xx[i]:=x; yy[i]:=y;
  end;
 for i:=1 to (1 shl 16-1) do
  nr[i]:=nr[i shr 1]+i and 1;
 rez:=0; aux:=n div 31;
 for i:=0 to m-1 do
  for j:=0 to aux do
   begin
         bla:=mat[xx[i],j]and mat[yy[i],j];
         inc(rez,nr[bla shr 15]+nr[bla and(1 shl 15-1)]);
   end;
 writeln(fo,rez div 3);
 close(fo);
end.