Cod sursa(job #1785766)

Utilizator ionanghelinaIonut Anghelina ionanghelina Data 21 octombrie 2016 22:00:08
Problema Triplete Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.21 kb
#include<bits/stdc++.h>
#define dim 10005
using namespace std;
int n,m,x,y,sol;
int f(bitset<4100> a,bitset<4100> b,int j)
{
    a=(a&b);
    int nr=0;
    for(int k=(j+1);k<=n;k++) nr=nr+a[k];
    return nr;
}
bitset<4100> bs[4100];

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],j);
            }
        }
    }
    printf("%d\n",sol);
    return 0;
}