Cod sursa(job #1587007)

Utilizator BLz0rDospra Cristian BLz0r Data 1 februarie 2016 19:24:21
Problema Triplete Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.87 kb
#include <fstream>
using namespace std;

#define Nmax 4100
#define Bmax 64

ifstream fin ( "triplete.in" );
ofstream fout ( "triplete.out" );

typedef unsigned long long ULL;

ULL v[Nmax][Bmax];

void Addbit ( int x, int y ){

    int Bucket = Bmax - (y / 64);
    int Bit = y % 64;

    v[x][Bucket] |= ( 1LL << Bit );

}

int NrBits ( ULL x ){
    return __builtin_popcountll (x);
}

int main(){

    int N, M, x, y;

    fin >> N >> M;

    while ( M-- ){
        fin >> x >> y;
        if ( x > y )
            swap ( x, y );
        x--; y--;
        Addbit ( x, y );
        //Addbit ( y, x );
    }

    long long Sol = 0;
    for ( int i = 0; i < N; ++i ){
        int Nr = 0;
        for ( int j = 0; j < Bmax; ++j )
            Nr += NrBits(v[i][j]);

        Sol += 1LL * Nr * (Nr-1) / 2;
    }

    fout << Sol;

    return 0;
}