Pagini recente » Cod sursa (job #1201662) | Cod sursa (job #2551294) | Cod sursa (job #1475934) | Cod sursa (job #47334) | Cod sursa (job #220330)
Cod sursa(job #220330)
#include <stdio.h>
#define N 4300
unsigned int n,m,a[N][N/32+1];
unsigned int minim (int a, int b)
{
if (a>b)
return b;
return a;
}
void citirith()
{
unsigned int x,y,s;
scanf("%u%u",&n,&m);
for (unsigned int i=1; i<=m; i++)
{
scanf("%u%u",&x,&y);
--x;--y;
s=x+y;
x=minim(x,y); y=s-x;
a[x][y>>5]|=1<<(y&31);
}
}
void rezolvarith()
{
unsigned int sol,z,cat,check;
long long solmax=0;
for (unsigned int i=0; i<n-1; i++)
for (unsigned int j=i+1; j<n; j++)
{
check=j/32;
if (!(a[i][check]&(1<<(j&31))))
continue;
sol=0;
for (unsigned int k=0; k<=n/32; k++)
{
z=a[i][k]&a[j][k];
cat=0;
while (z)
{
if (z%2)
++cat;
z/=2;
}
sol+=cat;
}
solmax+=(long long)sol;
}
printf("%lld\n",solmax);
}
int main()
{
freopen("triplete.in","r",stdin);
freopen("triplete.out","w",stdout);
citirith();
rezolvarith();
return 0;
}