Cod sursa(job #1442192)

Utilizator akaprosAna Kapros akapros Data 24 mai 2015 16:47:42
Problema Triplete Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <cstdio>
#include <cstring>
#include <algorithm>
#define Nmax 4099
#define Mmax 65539
#define B 58
using namespace std;
long long a[Nmax][Nmax / B];
int i, j, n, m;
long long sol;

inline long long nb1(long long  n)
{
    int nb = 0;
    if (n == 0) return 0;
    do
    {
        n &= n - 1;
        ++ nb;
    } while (n);

    return nb;
}

void citire()
{
    int x, y;
    scanf("%d %d", &n, &m);
    for (i = 1; i <= m ; ++ i)
    {
         scanf("%d %d", &x, &y);

         for (j = 0; j <= n / B; ++ j)
         sol += nb1(a[x][j] & a[y][j]);

         a[x][y / B] += (1 << (y % B)) ;
         a[y][x / B] += (1 << (x % B)) ;

    }
}
int main()
{
    freopen("triplete.in", "r", stdin);
    freopen("triplete.out", "w", stdout);

    citire();
    printf("%lld", sol);
    return  0;
}