Cod sursa(job #1833039)
Utilizator | Data | 21 decembrie 2016 15:41:20 | |
---|---|---|---|
Problema | Triplete | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.63 kb |
#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;
}