Pagini recente » Cod sursa (job #2169983) | Cod sursa (job #2418147) | Cod sursa (job #1602966) | Cod sursa (job #2803526) | Cod sursa (job #14420)
Cod sursa(job #14420)
//triplete
const nmax= 4096;
bb = 50;
type xx =record
x,y:integer;
end;
var nod : array[1..nmax,0..(nmax div bb)+1] of int64;
edge : array[1..65540]of xx;
rez,n,m:longint;
procedure add(x,y:integer);
var aux : int64;
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:int64;
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.