Cod sursa(job #1785799)

Utilizator ionanghelinaIonut Anghelina ionanghelina Data 21 octombrie 2016 23:08:46
Problema Triplete Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include<bits/stdc++.h>
using namespace std;
int n,m,x,y,sol;
int f(bool a[],bool b[])
{
    int nr=0;
    for(int i=1;i<=n;i++)
    {
       nr=nr+(a[i]&b[i]);
    }
    return nr;
}
bool bs[4100][4100];
int poz=0;
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;
}