Cod sursa(job #153234)

Utilizator andrei.12Andrei Parvu andrei.12 Data 10 martie 2008 12:17:02
Problema Triplete Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.97 kb
#include<stdio.h>

int n, m, pt[16], x1, x2, x, y, nr, i, j, k, use[4100], ind;
unsigned char v[4100][520], z;
struct ches{
	int x, y;
};
ches mc[80000];

inline int max(int a, int b){
	if (a > b)
		return a;
	return b;
}
int main()
{
	freopen("triplete.in", "rt", stdin);
	freopen("triplete.out", "wt", stdout);
	
	pt[0] = 1;
	for (i = 1; i <= 15; i ++)
		pt[i] = 2*pt[i-1];
	
	scanf("%d%d", &n, &m);
	for (i = 1; i <= m; i ++){
		scanf("%d%d", &x, &y);
		
		x1 = (y-1) / 8;
		x2 = (y-1) % 8;
		
		v[x][x1] |= pt[x2];
		use[x] = max(use[x], x1);
		
		x1 = (x-1) / 8;
		x2 = (x-1) % 8;
		
		v[y][x1] |= pt[x2];
		use[y] = max(use[y], x1);
		
		mc[++ind].x = x;
		mc[ind].y = y;
	}
	
	for (i = 1; i <= ind; i ++){
		x = mc[i].x;
		y = mc[i].y;
		
		k = max(use[x], use[y]);
		for (j = 0; j <= k; j ++){
			z = v[x][j] & v[y][j];
			
			while (z){
				z &= (z-1);
				
				nr ++;
			}
		}
	}
	
	printf("%d\n", nr / 3);
	
	return 0;
}