Cod sursa(job #1785759)

Utilizator ionanghelinaIonut Anghelina ionanghelina Data 21 octombrie 2016 21:42:09
Problema Triplete Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include<bits/stdc++.h>
using namespace std;
int f(bitset<4030> a,bitset<4030> b)
{
    a=(a&b);
    return a.count();
}
bitset<4030> bs[4030];
int n,m,x,y,sol;
int main()
{
    freopen("triplete.in","r",stdin);
    freopen("triplete.out","w",stdout);
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d",&x,&y);
        bs[x][y]=1;
        bs[y][x]=1;
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=(i+1);j<=n;j++)
        {
            if(bs[i][j])
            {
                sol+=f(bs[i],bs[j]);
            }
        }
    }
    printf("%d\n",sol/3);
    return 0;
}