Pagini recente » Cod sursa (job #2904105) | Cod sursa (job #543381) | Cod sursa (job #1236596) | Cod sursa (job #933142) | Cod sursa (job #1833039)
#include <iostream>
#include <fstream>
using namespace std;
const int nmax=4100;
const int bucket=22;
int b[(1<<bucket)+5],a[nmax][205];
int n,m,len,i,j,x,y,num,triplete;
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]);
triplete+=b[num];
}
}
g<<triplete;
return 0;
}