Cod sursa(job #2279166)

Utilizator AndreiDeltaBalanici Andrei Daniel AndreiDelta Data 8 noiembrie 2018 23:24:57
Problema Triplete Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <bits/stdc++.h>
#define Dim 4100
using namespace std;
ifstream f("triplete.in");
ofstream g("triplete.out");
vector < int > Vf[Dim];
int N,M,a,b,Aux[Dim],cnt;
long long ans;
bool Mch[Dim][Dim];


int main()
{
    f>>N>>M;
    for(int i=1;i<=M;i++)
    {
        f>>a>>b;
        Mch[a][b]=1;
        Mch[b][a]=1;
        Vf[a].push_back(b);
        Vf[b].push_back(a);
    }
    for(int i=1;i<=N;i++)
    {
        cnt=0;
        for(unsigned int j=0;j<Vf[i].size();j++)
            Aux[++cnt]=Vf[i][j];

        for(int op=1;op<=cnt;op++)
            for(int l=1;l<=cnt;l++)
        if(Mch[Aux[op]][Aux[l]]) ans++;
        //cout<<ans<<'\n';
        //ans/=2;
    }
    g<<ans/6;
    return 0;
}