Cod sursa(job #324085)
#include <stdio.h>
#include <string>
struct relatie{
long x,y;
} b[65600];
unsigned long a[5000][130];
long n,m,i,j,x,y,nr;
char s[20];
int cit(long &x, long &y)
{
fgets(s,20,stdin);
int lung=strlen(s)-1;
int w=0;
x=0;
for (; (s[w]!=' ') && (w<lung); ++w)
x=x*10+s[w]-48;
++w;
y=0;
for ( ; (s[w]!=' ') && (w<lung); ++w)
y=y*10+s[w]-48;
return 0;
}
int main()
{
freopen("triplete.in","r",stdin);
freopen("triplete.out","w",stdout);
cit(n,m);
for (i=1; i<=m; ++i)
{
cit(x,y);
a[x][y >> 5]=a[x][y >> 5] | (1 << (y & 31));
a[y][x >> 5]=a[y][x >> 5] | (1 << (x & 31));
b[i].x=x; b[i].y=y;
}
nr=0;
for (i=1; i<=m; ++i)
for (j=0; j<=(n >> 5); ++j)
{
x=a[b[i].x][j] & a[b[i].y][j];
if (x!=0)
do {
x &=(x-1);
nr++;
}
while (x!=0);
}
nr/=3;
printf("%ld\n", nr);
fclose(stdin); fclose(stdout);
return 0;
}