Cod sursa(job #551743)

Utilizator drag0s93Mandu Dragos drag0s93 Data 11 martie 2011 07:59:54
Problema Triplete Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.87 kb
#include <cstdio>
#include <algorithm>
using namespace std;
 
#define biti 32
 
int n, m;
int a[66000], b[66000], v[4100][150];
int i, j, sol;
 
int main()
{
    freopen("triplete.in", "r", stdin);
    freopen("triplete.out", "w", stdout);
 
    scanf("%d %d", &n, &m);
 
    for (i = 1; i <= m; i++)
    {
        scanf("%d %d", &a[i], &b[i]);
 
        if (a[i] < b[i])
            swap(a[i], b[i]);
 
        int B = biti - (b[i] % biti);
        int grupe = b[i] / biti + 1;
        int q = (v[ a[i] ][grupe] >> B) + 1;
 
        q <<= B;
        v[ a[i] ][grupe] = q | v[ a[i] ][grupe];
    }
 
    for (i = 1; i <= m; i++)
        for (j = 1; j <= a[i] / biti + 1; j++)
        {

             
            n = v[ a[i] ][j] & v[ b[i] ][j];
 
            while (n != 0)
            {
                n &= n - 1;
               ++sol;
            }
        }
 
    printf("%d", sol);
}