Cod sursa(job #12643)

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