Cod sursa(job #218223)

Utilizator AndreyPAndrei Poenaru AndreyP Data 1 noiembrie 2008 11:17:58
Problema Triplete Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1 kb
#include<stdio.h>
#define ll long long
int n,m,unde;
ll r=0;
unsigned char a[4098][515];
void citeste(int &x,int &y)
{
	x=y=0;
	char c[20];
	fgets(c,20,stdin);
	int i;
	for(i=0; c[i]>='0' && c[i]<='9'; i++)
		x=x*10+c[i]-'0';
	for(i++; c[i]>='0' && c[i]<='9'; i++)
		y=y*10+c[i]-'0';
}
void citire()
{
	int x,y;
	for(int i=0; i<m; i++)
	{
		citeste(x,y);
		a[x][y>>3]|=1<<(y&7);
		a[y][x>>3]|=1<<(x&7);
	}
	unde=(n>>3)+2;
	//if(unde&7)
	//	unde++;
}
long long nrb(unsigned char x)
{
	int k=0;
	while(x)
	{
		x&=x-1;
		k++;
	}
	ll k1=(ll)k;
	return k1;
}
void vezi(int x,int y,int z)
{
	unsigned char aux;
	for(int i=0; i<unde; i++)
	{
		aux=a[x][i]&a[y][i]&a[z][i];
		r+=nrb(aux);
	}
}
int main()
{
	freopen("triplete.in","r",stdin);
	freopen("triplete.out","w",stdout);
	scanf("%d%d\n",&n,&m);
	citire();
	int i,j,k;
	for(i=1; i<=n; i++)
	{
		for(j=i+1; j<=n; j++)
		{
			for(k=j+1; k<=n; k++)
				vezi(i,j,k);
		}
	}
	printf("%lld\n",r);
	return 0;
}