Pagini recente » Cod sursa (job #2173237) | Cod sursa (job #807702) | Cod sursa (job #2529341) | Cod sursa (job #2437013) | Cod sursa (job #218273)
Cod sursa(job #218273)
#include<stdio.h>
#define ll long long
int n,m,unde;
ll r=0;
unsigned long long a[4098][130];
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);
if(y<x)
a[y][x>>6]|=1<<(x&63);
else
a[x][y>>6]|=1<<(y&63);
}
unde=(n>>6)+1;
}
long long nrb(unsigned long long x)
{
int k=0;
while(x)
{
x&=x-1;
k++;
}
return (ll)k;
}
void vezi(int x,int y)
{
unsigned long long aux;
if(!(a[x][y>>6]&(1<<(y&63))))
return;
for(int i=0; i<unde; i++)
{
aux=a[x][i]&a[y][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;
for(i=1; i<=n; i++)
{
for(j=i+1; j<=n; j++)
vezi(i,j);
}
printf("%lld\n",r);
return 0;
}