Cod sursa(job #1098226)

Utilizator Al3ks1002Alex Cociorva Al3ks1002 Data 4 februarie 2014 17:43:58
Problema Triplete Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
#include<cstdio>
#include<bitset>
using namespace std;
const int NMAX= 4100;
const int MMAX = 65540;
const int DIM = 10000;
int n,m,i,x,y,a[MMAX],b[MMAX],poz;
long long sol; char buff[DIM];
bitset<NMAX> v[NMAX];
void Read(int &x)
{
    x=0;
    while(buff[poz]<'0' || buff[poz]>'9')
        if(++poz==DIM) fread(buff,1,DIM,stdin),poz=0;
    while(buff[poz]>='0' && buff[poz]<='9')
    {
        x=x*10+buff[poz]-'0';
        if(++poz==DIM) fread(buff,1,DIM,stdin),poz=0;
    }
}
int main()
{
	freopen("triplete.in","r",stdin);
	freopen("triplete.out","w",stdout);
	Read(n); Read(m);
	for(i=1;i<=m;i++)
	{
	    Read(x); Read(y);
        a[i]=x; b[i]=y;
	    v[x][y]=v[y][x]=1;
	}
    for(i=1;i<=m;i++)
        sol+=(v[a[i]]&v[b[i]]).count();
    printf("%lld\n",sol/3);
	return 0;
}