Cod sursa(job #694983)

Utilizator vladstoickvladstoick vladstoick Data 28 februarie 2012 09:46:31
Problema Triplete Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include<fstream>
using namespace std;
ifstream in("triplete.in");
ofstream out("triplete.out");
int n , m , x , y ;
unsigned int a[4100][200];
int biti(unsigned int x)
{
    int rez=0;
    while(x)
    {
        rez++;
        x=x&(x-1);
    }
    return rez;
}

int main()
{
    in>>n>>m;
    for(int i=1;i<=m;i++)
    {
        in>>x>>y;
        a[x][y/32] |= 1<<(y%32);
        a[y][x/32] |= 1<<(x%32);
    }
    long long rez=0;
    for(int i=1;i<n;i++)
        for(int j=i+1;j<=n;j++)
            if(a[i][j/32]&(1<<(j%32)))
            {
                for(int k=0;k*32<=n;k++)
                    rez = rez + biti( a[i][k] & a[j][k] );
            }
    out<<rez/3;
    return 0;
}