Cod sursa(job #2150819)

Utilizator shantih1Alex S Hill shantih1 Data 3 martie 2018 19:57:04
Problema Triplete Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <iostream>
#include <fstream>
#define ll long long
using namespace std;
ifstream fin("triplete.in");
ofstream fout("triplete.out");

ll m,n,i,j,gr,nr,p,lim,x,y,aend;
struct pair
{ int x,y;	}v[66000];
ll mch[4100][72];

void famuchie(int x,int y)
{
	p=60;
	nr=y/60;
	if(y%60>0)
	{
		nr++;
		p=y%60;
	}
	p--;
	mch[x][nr]+=((ll)1<<p);
}
ll cati(ll x)
{
	int nr=0;
	while(x)
	{
		nr++;
		x&=(x-1);
	}
	return nr;
}
int main() {
	
	fin>>n>>m;
	for(i=1;i<=m;i++)
	{
		fin>>v[i].x>>v[i].y;
		famuchie(v[i].x,v[i].y);
		famuchie(v[i].y,v[i].x);
	}
	
	lim=n/60+1;
	ll rez=0;
	for(i=1;i<=m;i++)
	{
		x=v[i].x;	y=v[i].y;
		for(j=1;j<=lim;j++)
		{
			aend=(mch[x][j]&mch[y][j]);
			rez+=cati(aend);
		}
	}
	rez/=3;
	fout<<rez<<"\n";
}