Cod sursa(job #324097)

Utilizator popa.andreeaPopa Andreea Maria popa.andreea Data 14 iunie 2009 18:07:26
Problema Triplete Scor 70
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.99 kb
program triplete;
var a:array[0..4096,0..256] of longint;
    x,y,x1,y1,r,i,j,n,m:longint;
    maxnr:int64;
    f,g:text;

function nr(n:longint):longint;
  var a:word;
  begin
  a:=0;
  while n<>0 do
        begin
        n:=n and (n-1);
        inc(a);
        end;
  nr:=a;
  end;

begin
assign(f,'triplete.in');
assign(g,'triplete.out');
reset(f);
rewrite(g);
read(f,n,m);
for i:=1 to m do
    begin
    read(f,x1,y1);
    x:=x1;
    y:=y1;
    r:=y and 15;
    y:=(y-r) shr 4  ;
    a[x,y]:=a[x,y]+1 shl r;
    y:=x1;
    x:=y1;
    r:=y and 15;
    y:=(y-r) shr 4  ;
    a[x,y]:=a[x,y]+1 shl r;
    end;
close(f);
reset(f);
read(f,n,m);
maxnr:=0;
for i:=1 to m do
    begin
    read(f,x,y);
    if x>y then
       begin
       x1:=x;
       x:=y;
       y:=x1;
       end;
    for j:=0 to (n shr 4+1) do
        begin
        y1:=a[x,j] and a[y,j];
        maxnr:=maxnr+nr(y1);
        end;
    end;
close(f);
writeln(g,maxnr div 3);
close(g);
end.