Cod sursa(job #2413888)

Utilizator ardutgamerAndrei Bancila ardutgamer Data 23 aprilie 2019 19:41:31
Problema Triplete Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <cstdio>
#include <bitset>

using namespace std;

bitset<4100>b[4100],temp;

int main()
{
    freopen("triplete.in","r",stdin);
    freopen("triplete.out","w",stdout);
    int m , n , x , y , cnt = 0;
    scanf("%d%d",&n,&m);
    for(int i = 1 ; i <= m ; i++)
    {
        scanf("%d%d",&x,&y);
        b[x][y] = b[y][x] = 1;
    }
    for(int i = 1 ; i < n ; i++)
        for(int j = i+1 ; j <= n ; j++)
        {
            if(b[i][j] == 1)
            {
                temp = (b[i]&b[j]);
                cnt += temp.count();
            }
        }
    printf("%d",cnt/3);
    return 0;
}