Pagini recente » Rating Cmeciu Alexandru Cristian (cmeciualex) | Profil MvpRhasta | Cod sursa (job #1140464) | Cod sursa (job #2018128) | Cod sursa (job #1833040)
#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;
}