Cod sursa(job #24217)

Utilizator vladcyb1Vlad Berteanu vladcyb1 Data 1 martie 2007 21:56:06
Problema Triplete Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.33 kb

 const
      FIN = 'triplete.in';
      FOUT = 'triplete.out';
      NMAX = 4096;
      bucata = 15;


   var
       NBIT : array[ 0..maxint ] of longint;
       V : array[ 1..NMAX, 0..275 ] of integer;
       A, B : array[ 1..NMAX ] of longint;
       f, g : text;
       N, M, ans : longint;

 procedure process;
  var i, j : longint;
  begin
   for i := 0 to maxint do
     for j := 0 to 15 do
       if ( 1 shl j ) and ( i ) > 0 then inc( NBIT[i] );
  end;

 procedure add( x, y : longint ); // adauga nodul y la nodul x
  var buc, bit : longint;
  begin
    buc := y div bucata;
    bit := y mod bucata;
    V[x][buc] := V[x][buc] + ( 1 shl y );
  end;

 procedure read_data;
  var i, x, y : longint;
  begin
   assign( f, FIN ); reset( f ); readln( f, N, M );
   for i := 1 to M do
     begin
      readln( f, x, y ); A[i] := x; B[i] := y;
      add( x, y );
      add( y, x );
     end;
  close( f );
  end;

  procedure solve;
   var i, j : longint;
   begin
    ans := 0;
     for  i := 1 to M do
       for j := 0 to ( N div bucata ) do ans := ans + NBIT[ V[A[i],j] and V[B[i],j ] ];
    end;

   procedure save;
    begin
     assign( g, FOUT ); rewrite( g );
     writeln( g, ans div 3);
     close( g );
    end;

   begin
    read_data;
    process;
    solve;
    save;
   end.