Cod sursa(job #1587126)

Utilizator BLz0rDospra Cristian BLz0r Data 1 februarie 2016 20:12:41
Problema Triplete Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.32 kb
#include <fstream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

#define Nmax 4096
#define Mmax 65537
#define Bmax 64

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

typedef unsigned long long ULL;

ULL v[Nmax][Bmax];
pair < int, int > E[Mmax];

void Addbits ( int x, int y ){

}

long long Sol = 0;
void Combine ( int x, int y ){

    long long rez = 0;
    for ( int i = 0; i < Bmax; ++i )
        Sol += __builtin_popcountll (v[x][i] & v[y][i]);

}

string Buffer;
string :: iterator it;

int ReadInt(){

    int nr = 0;

    while ( *it < '0' || *it > '9' )
        it++;

    while ( *it >= '0' && *it <= '9' ){
        nr = nr * 10 + ( *it - '0' );
        it++;
    }

    return nr;
}

int main(){

    int N, M, x, y;

    getline( fin, Buffer, (char)0 );
    it = Buffer.begin();

    N = ReadInt();
    M = ReadInt();

    for ( int i = 1; i <= M; ++i ){

        E[i].first = (ReadInt() - 1);
        E[i].second = (ReadInt() - 1);

        v[E[i].first][(E[i].second / 64)] |= ( 1LL << (E[i].second % 64) );
        v[E[i].second][(E[i].first / 64)] |= ( 1LL << (E[i].first % 64) );

    }

    for ( int i = 1; i <= M; ++i )
        Combine ( E[i].first, E[i].second );

    fout << Sol / 3;

    return 0;
}