Cod sursa(job #1785767)

Utilizator ionanghelinaIonut Anghelina ionanghelina Data 21 octombrie 2016 22:01:48
Problema Triplete Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.15 kb
#include<bits/stdc++.h>
#define dim 100005
using namespace std;
int f(bitset<4100> a,bitset<4100> b)
{
    a=(a&b);
    return a.count();
}
bitset<4100> bs[4100];
int n,m,x,y,sol;
char buff[dim+5];
int poz=0;
void citeste(int &numar)
{
     numar=0;
    while(buff[poz]<'0' || buff[poz]>'9')
    {
        poz++;
        if(poz==dim)
        {
            poz=0;
            fread(buff,1,dim,stdin);
        }
    }
    while(buff[poz]>='0' && buff[poz]<='9')
    {
        numar=numar*10+buff[poz]-'0';
        poz++;
        if(poz==dim)
        {
            poz=0;
            fread(buff,1,dim,stdin);
        }
    }
}
int main()
{
    freopen("triplete.in","r",stdin);
    freopen("triplete.out","w",stdout);
    fread(buff,1,dim,stdin);
    citeste(n);
    citeste(m);
    for(int i=1;i<=m;i++)
    {
        citeste(x);
        citeste(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;
}