Cod sursa(job #695003)

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

int main()
{
    int m,i,j,x,y;
    in>>n>>m;
    for(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(i=1;i<n;i++)
        for(j=i+1;j<=n;j++)
            if(a[i][j/32]&(1<<(j%32)))
                for(int k=0;k*32<=n;k++)
                    rez+=biti(a[i][k]&a[j][k]);
    out<<rez/3<<"\n";
}