Cod sursa(job #14425)

Utilizator andrei_infoMirestean Andrei andrei_info Data 8 februarie 2007 23:02:00
Problema Triplete Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.33 kb
//triplete

const nmax= 4096;
      bb = 25;
type  xx =record
        x,y:integer;
        end;
var nod : array[1..nmax,0..(nmax div bb)+1] of longint;
    edge : array[1..65540]of xx;
    rez,n,m:longint;

procedure add(x,y:integer);
var aux : longint;
    bit,grup:integer;
begin
bit:=(y mod bb) -1 ; if bit = -1 then bit:=bb;
aux:= 1 shl bit;
grup:= y div bb; if y mod bb = 0 then dec(grup);
nod[x][grup] := nod[x][grup] + aux;
end;

procedure citire;
var i:longint;
    x,y:integer;
begin
assign(input,'triplete.in'); reset(input);
readln(n,m);
for i:=1 to m do
        begin
        readln(x,y);
        add(x,y);
        add(y,x);
        edge[i].x:=x; edge[i].y:=y;
        end;
close(input);
end;

function numara(x,y:integer):integer;
var i,aux:integer;
    r,j:longint;
begin
aux:=0;
  for i:=0 to (n div bb) + 1 do
        begin
        r:= nod[x][i] and nod[y][i];
        j:=1;
        while j <= r do
                begin
                if j and r <> 0 then inc(aux);
                j:=j shl 1;
                end;
        end;
numara:=aux;

end;

procedure calc;
var i:longint;
begin
for i:=1 to m do
                        rez:=rez+numara(edge[i].x,edge[i].y);
end;

begin
citire;
calc;
assign(output,'triplete.out'); rewriTe(output);
writeln(rez div 3);
close(output);
end.