Cod sursa(job #341721)

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

using namespace std;

const int N = (1<<12);

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>>3] |= 1<<(y&7);
		a[y][x>>3] |= 1<<(x&7);
		adj[x].push_back(y);
	}
}

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

unsigned int calcul()
{
	int i,j,k,m,nb=1+(n>>3);
	unsigned int nr=0;
	for(i=0;i!=n;++i)
		for(j=0,m=adj[i].size();j!=m;++j)
			for(k=0;k!=nb;++k)
				nr+=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("%u\n",calcul());
	return 0;
}