Cod sursa(job #341714)

Utilizator rumburakrumburak rumburak Data 19 august 2009 13:17:56
Problema Triplete Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.8 kb
#include<cstdio>
#include<vector>

using namespace std;

const int N = (1<<12);
const int d = (1<<3);

int n;
unsigned char a[N][N>>3];
vector<int> adj[N];

void citire()
{
	int m,x,y;
	scanf("%d%d",&n,&m);
	while(m--)
	{
		scanf("%d%d",&x,&y);
		--x;
		--y;
		a[x][y/d] |= 1<<(y%d);
		a[y][x/d] |= 1<<(x%d);
		adj[x].push_back(y);
	}
}

int biti1(unsigned char x)
{
	int nr=0;
	while(x)
	{
		++nr;
		x &= x-1;
	}
	return nr;
}

long long calcul()
{
	int i,j,k,m;
	long long nr=0;
	for(i=0;i<n;++i)
		for(j=0,m=adj[i].size();j<m;++j)
			for(k=0;k<=n/d;++k)
				nr+=(long long)biti1(a[i][k]&a[adj[i][j]][k]);
	return nr/3;
}

int main()
{
	freopen("triplete.in","r",stdin);
	freopen("triplete.out","w",stdout);
	citire();
	printf("%lld\n",calcul());
	return 0;
}