Pagini recente » Cod sursa (job #2396244) | Cod sursa (job #1220046) | Cod sursa (job #1181931) | Rating Dica si atat (Dica122) | Cod sursa (job #153231)
Cod sursa(job #153231)
#include<stdio.h>
int n, m, pt[16], x1, x2, x, y, nr, i, j, k, use[4095], ind;
unsigned char v[4095][513], z;
struct ches{
int x, y;
};
ches mc[50000];
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;
}