Cod sursa(job #1833040)

Utilizator Bodo171Bogdan Pop Bodo171 Data 21 decembrie 2016 15:42:26
Problema Triplete Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <iostream>
#include <fstream>
using namespace std;
const int nmax=4100;
const int bucket=22;
char b[(1<<bucket)+5];
int a[nmax][205];
int n,m,len,i,j,x,y,num,triplete,nr;
int main()
{
    ifstream f("triplete.in");
    ofstream g("triplete.out");
    f>>n>>m;
    for(i=1;i<(1<<bucket);i++)
        b[i]=b[(i&(i-1))]+1;
    len=n/bucket;
    for(i=1;i<=m;i++)
    {
        f>>x>>y;
        a[x][y/bucket]+=(1<<(y%bucket));
        a[y][x/bucket]+=(1<<(x%bucket));
        for(j=0;j<=len;j++)
        {
            num=(a[x][j]&a[y][j]);
            nr=b[num];
            triplete+=nr;
        }
    }
    g<<triplete;
    return 0;
}